Monday, 17 February 2014

Pass by reference

 struct Increment
        {
            void increment(ref int n)
            {
                n = n + 1;
                Console.WriteLine("\n****in method my value is {0}", n);
            }
            static void Main()
            {
                int n;
                Console.WriteLine("Enter any no");
               n = int.Parse(Console.ReadLine());
                Console.WriteLine("\nBefore Calling method...My Value is {0}", n);
                Increment o = new Increment();
                o.increment(ref n);
                Console.WriteLine("\nAfter Calling method....My Value is {0}", n);
                Console.WriteLine("Press any key to Exit");
                Console.ReadKey();
            }
        }

No comments:

Post a Comment