Possible Duplicate:
C# – Reference type still needs pass by ref?
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;
}
I am new to C# and learning out modifier. I came across this snippet on MSDN.
I understand out is useful here for int primitive variable, but for string variables, references will be passed to the called method even without the out modifier, right?
Yes, but without
outthey will not be passed back:stringis designed as immutable. You are probably thinking about mutable reference types: