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:


Search Engine Optimization and SEO Tools
webbhotell
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Posts
Posts
 
 

No comments:
Post a Comment