P Narasimha
What is mean by OUT Parameters,Ref Parameters in C#?
By P Narasimha in ASP.NET on Dec 08 2008
  • Bechir Bejaoui
    Dec, 2008 9


    Ok,

    consider this method

    public int  sum(int x, int y)
    {
        int z = x + y;
        return z;  
    }

    are the x or y changed during the method process, the response is  no for sure, we call those paramters input parameters

    Now, what if you want that x recives the sum of x+y so the x will be at the same time an input and also an output so it has to be marked as ref

    public int  sum(ref int x, int y)
    {
        int x = x + y;
        return x;  
    }

    Now, what if  the x value is known as input so we dont need to set it, then it will be considered only as an output value

    public int sum(out int x, int y)
    {
       x = 20;
       x = x + y;
       return x;
    }
     

    • 0
  • Ravi BS
    Dec, 2008 8

    hi,

      Out And Ref are same but the difference is using out parameter we need to assigne the value the variable.

    using ref parameter without assgineing the value ref parameter will work

     

     

    • 0
  • P Narasimha
    Dec, 2008 8

    Hi,

    What is mean by OUT Parameters,Ref Parameters in C#?

    Thanks,

    Narasima

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS