class Program
{
static void Main(string[] args)
{
p pe = new p();
Console.WriteLine(pe.str);
Console.Write(pe.write(pe.str) + Environment.NewLine);
Console.WriteLine(pe.str + Environment.NewLine);
Console.Write(pe.write(ref pe.str) + Environment.NewLine);
Console.WriteLine(pe.str + Environment.NewLine);
Console.ReadKey();
}
public class p
{
public string str = "计数";
public string write(string abc)
{
for (int i = 0; i < 3; i++)
{
abc += i;
Console.WriteLine("i" + i + abc);
}
Console.WriteLine("str" + abc);
return abc;
}
public string write(ref string abc)
{
for (int i = 0; i < 3; i++)
{
abc += i;
Console.WriteLine("i" + i + abc);
}
Console.WriteLine("str" + abc);
return abc;
}
}}
字符串做参数,相当于值类型参数,原来的字符串不变。加 ref 原来的字符串改变。断点命中值不显示的问题自己没找到答案。