Windows Phone Developers

Friday, May 7, 2010

How to pass an argument by reference in Csharp/C#/VB.NET

Pass by Reference/Pass by Value in VB.NET/C-Sharp/C#

Here is an example of passing an argument to a function by Value:

private static void PassByValueExample(double Salary)//
        {
            Salary = Salary * 1.2;
        }


Here is how it is passed as reference
private static void PassByRefExample(ref double Salary)//
        {
            Salary = Salary * 1.2;
        }


The following code shows the difference between the two

Console.WriteLine("Salary before hike is {0:F}", Sal);
            PassByValueExample( Sal);
            Console.WriteLine("Salary after hike is {0:F}", Sal);

            Console.WriteLine("Salary before hike is {0:F}", Sal);
            PassByRefExample(ref Sal);
            Console.WriteLine("Salary after hike is {0:F}", Sal);






See also:


Submit your website to 20 Search Engines - FREE with ineedhits!




Search Engine Optimization and SEO Tools




Software


webbhotell Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005