public void ChangeStringBuilder1(StringBuilder str)
{
str.Append("yes");
}
public void ChangeStringBuilder2(ref StringBuilder str)
{
str.Append("yes");
}
public void ChangeStringStr1(string str)
{
str += "yes";
}
public void ChangeStringStr1(ref string str)
{
str += "yes";
}
public void ChangeStringStr2(out string str)
{
string strTemp = "ok";
str = strTemp + "yes";
}
static void Main(string[] args)
{
StringBuilder strBuilder1 = new StringBuilder("str1");
StringBuilder strBuilder2 = new StringBuilder("str2");
new Program().ChangeStringBuilder1(strBuilder1);
new Program().ChangeStringBuilder1(strBuilder2);
Console.WriteLine(strBuilder1.ToString());
Console.WriteLine(strBuilder2.ToString());
string str1 = "str1";
string str2 = "str2";
string str3 = "str3";
new Program().ChangeStringStr1(str1);
new Program().ChangeStringStr1(ref str3);
new Program().ChangeStringStr2(out str2);
Console.WriteLine(str1.ToString());
Console.WriteLine(str2.ToString());
Console.WriteLine(str3.ToString());
}
结果:
str1yes
str2yes
str1
okyes
str3yes
Press any key to continue . . .