NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

out

The out method parameter keyword on a method parameter causes a method to refer to the same variable that was passed into the method. Any changes made to the parameter in the method will be reflected in that variable when control passes back to the calling method.

Declaring an out method is useful when you want a method to return multiple values. A method that uses an out parameter can still return a value. A method can have more than one out parameter.

To use an out parameter, the argument must explicitly be passed to the method as an out argument. The value of an out argument will not be passed to the out parameter.

A variable passed as an out argument need not be initialized. However, the out parameter must be assigned a value before the method returns.

An overload will occur if declarations of two methods differ only in their use of out.

A property is not a variable and cannot be passed as an out parameter.

For information on passing an array, see Passing Arrays Using ref and out.

Example

using System;
public class MyClass {
   public static int TestOut(out char i) {
      i = 'b';
      return -1;
   }

   public static void Main() {
      char i;   // variable need not be initialized
      Console.WriteLine(TestOut(out i));
      Console.WriteLine(i);
   }
}

Output

-1
b

See Also

C# Keywords | Grammar