C#基础-out与ref字段

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ConsoleApplication2
{
class Program
{ static void Main(string[] args)
{
string outString = "This is the outString value"; Console.WriteLine(outString); bool ok = outMethod(out outString); Console.WriteLine(outString); Console.WriteLine(ok.ToString()); /*我是分隔线*/
string refString = "This is the refString value"; Console.WriteLine(refString); bool okk = refMethod(ref refString); Console.WriteLine(refString); Console.WriteLine(okk.ToString()); Console.ReadKey(); }
static bool outMethod(out string str)
{ str = "This is the new outString value"; //必须设值
return true;
}
static bool refMethod(ref string str)
{ str = "This is the new outString value"; //此句可以不写,即不用重新设值
return true;
}
}
}
上一篇:c提取文件路径、文件名和后缀名


下一篇:第一个 lua 程序