Saturday, April 21, 2007

C# - Using out Access to Parameters

The return type enables you to send back a single variable from a method; however,sometimes you will want more than one value to be returned. Although reference variables could be used to do this, C# has also added a special attribute type specifically for returning data from a method. You can add parameters to your method header specifically for returning values by adding the out keyword. This keyword signifies that a value is being returned out of the method but is not coming in. When you call a method that has an out parameter, you must be sure to include a variable to hold the value being returned. ex: int a,b; public void out_test(x, out y, out z) { y=x+1; z=x+2; } out_test(4, out a, out b);

No comments:

Post a Comment