Reference Parameter Example In C Sharp


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

class ReferenceParameter
{
static void Main()
{
int a = 10;
Console.WriteLine("Value of a before calling method is " + a);
Console.WriteLine("--------------------");
ChangeValueMethod(ref a);
Console.WriteLine("--------------------");
Console.WriteLine("Value of a after calling method is " + a);
        }
static void ChangeValueMethod(ref 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 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;
 }

--------------------------------------------------------------------------------------------------------
Reference Parameter Example In C Sharp Reference Parameter Example In C Sharp Reviewed by Baljeet Singh on 01:54 Rating: 5

No comments:

Powered by Blogger.