.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

what is OUT parameter and where we use it?

Posted By: PankajGupta     Posted Date: August 05, 2009    Points:2   Category :C#
what is OUT parameter and where we use it?

Author: Venkat             
Posted Date: August 05, 2009     Points: 5   

The out keyword causes arguments to be passed by reference. This is similar to the ref keyword, except that ref requires that the variable be initialized before being passed. To use an out parameter, both the method definition and the calling method must explicitly use the out keyword. For example
class MyClass
static void Method(out int i)
i = 44;
static void Main()
int value;
Method(out value);
// value is now 44

Mark As Answer if this solve your problem
Warm Regards,
Author: Abhisek Panda             
Posted Date: December 13, 2009     Points: 5   

When out parameter is used inside the method declaration and call initialisation is not compulsory inside the main() method. It can be initialised inside the function declaration.

class Demo
public int Change(out int i)
return i * i;
class Change
static void main(string a[])
Demo d=new Demo();
int a;
int r= d.Change(out a);


In this program we are declaring a variable a inside the main method and passing it to the Change method.

d.Change(out a);

Then a receives value from i=5 inside the Change().
You have to use out in the method and also when calling the method.

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend