c# 'out object'

David Lindon

Golden Master
Messages
15,233
How do you declare an 'out object'? For example:

GetField(string FieldName, out object value);

So if I wanted to get the field 'IO-Name' and store it in the 'Name' variable how can I do it?
 
I personally think that methods that return a value are a simpler alternative. I hadn't even heard of 'out' objects until recently. But I believe the correct implementation goes something like this:

Code:
void Main() {

   String myName;

   SetMyName(out myName);
   Console.WriteLine(myName);

} // end Main

void SetMyName(out String myVal) {
   myVal = "Daeva";
} // end SetMyName

I didn't compile that, but hopefully that helps.

*EDIT: Note that it is important to not initialize the value being assigned with out.
 
Back
Top Bottom