Breaking News

Editors Picks

Tuesday, June 21, 2011

ref keyword in c sharp


ref C#

The ref keyword causes arguments to be passed by reference. The effect is that any changes to the parameter in the method will be reflected in that variable when control passes back to the calling methodTo use a ref parameter, both the method definition and the calling method must explicitly use the ref keyword.An argument passed to a ref parameter must first be initialized

 For example:

class
 RefExample

{

    static void Method(ref int i)
    {
        i = 44;
    }
    static void Main()
    {
        int val = 0;
        Method(ref val);
        // val is now 44
    }
}

No comments :

Post a Comment

Contact Us

Name

Email *

Message *