The ref keyword on a method parameter causes a method to refer to the same variable that was passed as an input parameter for the same method. If you do any changes to the variable, they will be reflected in the variable.
You can even use ref for more than one method parameters.
namespace TestRefP
{
using System;
public class myClass
{
public static void RefTest(ref int iVal1 )
{
iVal1 += 2;
}
public static void Main()
{
int i; // variable need not be initialized
i = 3;
RefTest(ref i );
Console.WriteLine(i);
}
}
}
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Joe WilsonPosted Dec 28, 2015, 10:29 AM
Thank you very much.
mohit bajajPosted Dec 9, 2012, 2:01 AM
thank you bro