Q:

Method - call by reference using C# Language

0

This Program is used to swap the number using method call by ref. concept

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;

public class exam

 {

    public static void swap(ref int a,ref int b)

     {

         int t;

         t = a;

         a = b;

         b = t;

         Console.WriteLine("\nA value is : {0}",a);

         Console.WriteLine("\nB value is : {0}",b);

     }



     public static void Main()

       {

          int x,y;



           Console.Write("\nEnter the A value : ");

           x = int.Parse(Console.ReadLine());



           Console.Write("\nEnter the B value : ");

           y = int.Parse(Console.ReadLine());

           Console.WriteLine("\n"); 



           Console.WriteLine("The Given values are...");

           Console.WriteLine("\nA value is : {0}",x);

           Console.WriteLine("\nB value is : {0}",y);



           Console.WriteLine("\n"); 

           Console.WriteLine("After the Swap, the values are...");

           swap(ref x,ref y);

       }

    }

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now