Link to home
Start Free TrialLog in
Avatar of balakiran_bs
balakiran_bs

asked on

How to implement call-by-reference in C# ?

plz look at the following code.

class Test
{
     public static void swap(int &a,int &b)
     {
          int c=a; a=b; b=c;
     }
     public static void Main()
     {
          int x=10,y=20;
          swap(x,y);
          System.Console.WriteLine("x={0} and y={1}",x,y);
     }
};

   It is not working. I tried the same
swap function using pointers too as follows

     public static void swap(int *p,int *q)
     {
          int c=*p; *p=*q; *q=c;
     }
ASKER CERTIFIED SOLUTION
Avatar of Lagi
Lagi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial