Home > DeveloperSection > Forums > out and ref keywords in c#.
James Smith

Total Post:48

Posted on    April-28-2011 1:53 AM

 C# C# 

 1 Reply(s)
 2836  View(s)
Rate this:
Could anyone please explain me in some detail with an example that what is difference between out and ref keywords in c#.
Thanks in advance.

Amit Singh

Total Post:103

Posted on    April-28-2011 3:14 AM

ref keywords:
When we want change in passed parameter to the method then we pass it by reference with the help of ref keyword in actual and formal parameters. By passing parameter by reference actual address of the parameter is passed to the method and changes made to the parameter in method reflect in actual parameter passed.
out Keywords
Passing parameter by out is somewhat like ref but the difference is that it is unidirectional i.e. we do not need to initialize the passed variable but we get back the processed value. Likewise Reference parameter we need to use out before variable in output parameter.

For Example:
Please check this link:

Don't want to miss updates? Please click the below button!

Follow MindStick