dragonwell
Programmer
If you call a method that returns an object as if if returned void, what happens to the returned object?
Example:
So, when I call
in the example without referencing it's returning string object, where does the return object go? Does it ever exist?
Just something I'm wondering about.
Thanks,
David
Example:
Code:
public class MethodHolder
{
private int testValue=0;
public int TestValue
{
get{return testValue;}
}
public string MakeString()
{
//a side effect
testValue = 1;
return "Return String";
}
}
public class TestProgram
{
public static void Main()
{
MethodHolder mh = new MethodHolder();
//call the method without getting the return value
mh.GetString();
//only using it to get side effect
Console.Write(mh.TestValue.ToString());
}
}
So, when I call
Code:
GetString()
Just something I'm wondering about.
Thanks,
David