Saturday, January 12, 2013

Output Parameters in C#.NET


A parameter declared with an out modifier is called an output parameter. As with reference parameters, output parameters do not create any new storage locations on memory. Output parameters reference the same storage location as the variable given as the argument in the function member invocation.

Definite assignment rules are applicable to output parameters:
  • No variable needs to be definitely assigned before it can be passed as an output parameter in a member invocation function.
  • Within a function member, output parameters are initially unassigned.
  • Output parameters of a function member have to be definitely assigned before the function member returns normally.
class VarEx
{
public static int StaticVar;
int InstanceVar;
void F(int[] ArrayEl,
int ValueParam,
ref int RefParam,

out int OutputParam) {
int LocalVar = 1;
OutputVar = ValueParam + RefParam++;
  }
}

No comments:
Write comments
Recommended Posts × +