Friday, August 6, 2010

Program to pass values between methods.


Write a program to pass values between methods.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Csharp
{
    class passignvalues
    {
        public static void Main(string [] args)
        {
            passignvalues obj = new passignvalues();
            int c,d;
            Console.WriteLine("Enter the values");
            c = Convert.ToInt32(Console.ReadLine());
            d = Convert.ToInt32(Console.ReadLine());
            obj.swap(ref c, ref d);
            Console.WriteLine("{0}", c);
            Console.WriteLine("{0}",d);
            Console.ReadLine();
        }
        public void swap(ref int a, ref int b)
        {  int temp;
            temp = a;
            a = b;
            b = temp;
        } 
    }
}

No comments:

Post a Comment