Wednesday, 20 November 2013

C# Call by reference Program...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleAppCallbyref
{
   public class abc
    {
       public int sum(ref int a, ref int b)
       {
           int c = a + b;
           return c;
       }
        static void Main(string[] args)
        {
            abc obj = new abc();
        //    int x = 6;
         //   int y = 7;
            Console.WriteLine("------Enter First Number--------");
            int x = int.Parse(Console.ReadLine());
            Console.WriteLine("------Enter Second Number-------");
            int y = int.Parse(Console.ReadLine());
            int z = obj.sum(ref x, ref y);
            Console.WriteLine("-----The sum of two numbers is--------");
            Console.WriteLine(z);
            Console.ReadKey();
        }
    }
}

Output:

No comments:

Post a Comment