class Program
{
static void Main()
{
string input1 = "123456";
GetStr1(input1);
Console.WriteLine(input1);
string input2 = "123456";
GetStr2(ref input2);
Console.WriteLine(input2);
string input3 = "123456";
GetStr3(out input3);
Console.WriteLine(input3);
Console.ReadLine();
}
static string GetStr1(string input)
{
input = "Hello";
return input;
}
static string GetStr2(ref string input)
{
input = "Hello";
return input;
}
static string GetStr3(out string input)
{
input = "Hello";
return input;
}
}
{
static void Main()
{
string input1 = "123456";
GetStr1(input1);
Console.WriteLine(input1);
string input2 = "123456";
GetStr2(ref input2);
Console.WriteLine(input2);
string input3 = "123456";
GetStr3(out input3);
Console.WriteLine(input3);
Console.ReadLine();
}
static string GetStr1(string input)
{
input = "Hello";
return input;
}
static string GetStr2(ref string input)
{
input = "Hello";
return input;
}
static string GetStr3(out string input)
{
input = "Hello";
return input;
}
}
Result is:
123456
Hello
Hello
Actual:
string input2 = null;
string input3 = null;
string input3 = null;
Result is the same.
在模仿中成长,在创新中成功