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

Top 5 Contributors of the Month

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Use of ref parameter in C#

Posted By:Abhisek Panda       Posted Date: October 27, 2009    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com  

Ref Parameter:

The ref keyword is used to pass the reference of a variable to a function. It is used in call by reference.

Any changes made to the formal parameter affect the subroutine during method call.

The ref keyword is used both in formal and actual parameter.

class Demo


public int Change(ref int i)


return i * i;



class Change


static void main(string a[])


Demo d=new Demo();

int a=5;

int r= d.Change(ref a);






In this case the value of a has changed from 5 to 25. We can't pass the value inside the method. We have to pass the value inside the main().


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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