What is OUT Keyword ?

 Posted by Bharathi Cherukuri on 4/26/2012 | Category: C# Interview questions | Views: 1791 | Points: 40

Out keyword is used for passing a variable for output purpose. It has the same concept of ref keyword. Passing a ref parameter needs variable to be initialized while out parameter is passed without initialized.
It is useful when we want to return more than one value from the method.


class Test

public static void Main()
int a; // may be left un-initialized
DoWork(out a); // note out
Console.WriteLine("The value of a is " + a);

public static void DoWork(out int i) // note out
i=4; //must assigned value.

The program will result : The value of a is 4

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response