class Program
{
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="fwer", str2;
Method(out value, out str1, out str2);
Console.WriteLine (str1);
Console.ReadKey();
// value is now 44
// str1 is now "I've been returned"
// str2 is (still) null;
}
In the above I am initializing str1
and sending the str1
as out and changing the value in the caller method. as string is immutable. changing it should create a new string object. but how it's printing the value correctly in the calling method which changed in caller method.
thanks in advance.