In C#, out keyword 是argument传值变成passed by reference. out keyword 在同时返回多个值时很有用.
与ref keyword 相似. 若是使用out keyword传argument, 那么在method 的definition 和 使用时都需要家out keyword.
Async methods can't use out keyword.
Differences between out keyword and ref keyword:
ref requires that variable be initialized before it is passed.
class OutReturnExample
{
static void Method(out int i, out string s1, out string s2)
{
i = ;
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;
}
}