Method Out Parameters in C#



Declaring an out method is useful when you want a method to return one or multiple values. The following example uses out to return one variable with a single method call.

using System;  
  
class MethodOutParameters   
{  
    public static void Main(string[] args)   
    {  
        int value = 100;  
        Console.WriteLine("Before Method Execution, value={0}", value);  
        ChangeParameters(out value);  
        Console.WriteLine("After Method Execution, value={0}", value);  
    }  
    static void ChangeParameters(out int value)   
    {  
        value = 200;  
    }  
}  
Before Method Execution, value=100
After Method Execution, value=200

0 Comment's

Comment Form