可能是重复问题:
C# - 引用类型仍需要按引用传递吗?
C# - 引用类型仍需要按引用传递吗?
class OutReturnExample
{
static void Method(out int i, out string s1, out string s2)
{
i = 44;
s1 = "I've been returned";
s2 = null;
}
static void Main()
{
int value;
string str1, str2;
Method(out value, out str1, out str2);
// value is now 44
// str1 is now "I've been returned"
// str2 is (still) null;
}
我是C#新手,正在学习out修饰符。我看到了MSDN上的这个片段。
我知道out
对于int原始变量很有用,但对于字符串变量,即使没有out
修饰符,引用也会传递给被调用的方法,对吗?