Value Parameter Example In C Sharp


This program descirbe the concept of pass by value  (Value Parameter in C#)
---------------------------------------------------------------------------------------------
using System;

class ValueParameter
{
static void Main()
{
int a = 10;
Console.WriteLine("Value of a before calling method is " + a);
Console.WriteLine("--------------------");
ChangeValueMethod(a);
Console.WriteLine("--------------------");
Console.WriteLine("Value of a after calling method is " + a);
        }
static void ChangeValueMethod(int a)
{
a += 10;
Console.WriteLine("Value of a is " + a);
}
}

-------------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------------------------

Note : - While we make change in the variable value of the formal parameter they will not reflect changes to the variable value of the actual parameter.

Actual parameter is 
int a;
ChangeValueMethod(a);

Formal parmeter is 
static void ChangeValueMethod(int a)
{
a += 10;
        }
--------------------------------------------------------------------------------------------
Value Parameter Example In C Sharp Value Parameter Example In C Sharp Reviewed by Baljeet Singh on 01:48 Rating: 5

No comments:

Powered by Blogger.