While going through the msdn link http://msdn.microsoft.com/en-us/library/t3c3bfhx%28v=vs.71%29.aspx that contains documentation about "out" method parameter, I got stuck with the line "The value of an out argument will not be passed to the out parameter".
To understand this behaviour I have written a small piece of code containing a caller function with an out argument and a callee function with an out parameter.
The above code contains two functions “TestOutputArgument” and “TestOutputParameter”. But this code has a compilation error! In function "TestOutputParameter" value of out parameter "a" is used without assignment. Please note that this is despite of the fact that "a" has been assigned some value in the caller function “TestOutputArgument”.
In the above rectified code, value of "a" in “TestOutputArgument” function before calling function “TestOutputParameter” is 75. Upon stepping through "TestOutputParameter" in debug mode, value of "a" is still shown as 75 in the debug window. But the complier won’t let you access its value and will throw a compilation error if the out parameter is accessed without assigning any value.
This complies with the Microsoft’s definition for out parameter that "A variable passed as an out argument need not be initialized. However, the out parameter must be assigned a value before the method returns."
Below is the output of the above code
Hope this will help clarifying the out parameter in C#.
Thanks for reading