"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Tuesday, February 8, 2011

return a value from a function or call by reference

Hi,
i'm creating an data Access layer over their i faced this requirement.That is example i'm checking the number of existence of a name in a table over their i create a function and pass parameter over their one parameter i need the occurrence. For this i need to use pass by reference method.
 The reference variable is declared as ref in prefix .
Example


    protected sum add = new sum();

    protected void Page_Load(object sender, EventArgs e)
    {
        int _i = 10;
        int _j = 20;
        int _result=0;
        add.add(ref _result, _i, _j);
        lbl_Rslt.InnerText = _result.ToString();// displaying the result
    }

    public void add(ref int _result, int _P, int _k)
    {
        _result = _P + _k;
    }


 Download sample here


Stay tune...


Have a nice day... 'N happy Coding :)

No comments: