- Call by Value – Value passed will get modified only inside the
function , and it returns the same value whatever it is passed it into
the function.
- Call by Reference – Value passed will get modified in both inside
and outside the functions and it returns the same or different value.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ValRefType
{
class Program
{
public void ValueTypeSWAP(string s,string s1)
{
string temp = s1;
s1 = s;
s = temp;
Console.WriteLine("Swaping Name,SurName: {0} {1}", s, s1);
}
public void ReferenceTypeSWAP(ref string s,ref string s1)
{
string temp = s1;
s1 = s;
s = temp;
Console.WriteLine("Swaping Name,SurName: {0} {1}", s, s1);
}
static void Main(string[] args)
{
string name = "vinoth";
string fatname = "myilsamy";
Console.WriteLine("Original Name,SurName: {0} {1}", name, fatname);
Program Pro = new Program();
Pro.ValueTypeSWAP(name, fatname);
Console.WriteLine("Value Type After Swaped Name,SurName: {0} {1}", name, fatname);
Pro.ReferenceTypeSWAP(ref name, ref fatname);
Console.WriteLine("Ref Type After Swaped Name,SurName: {0} {1}", name, fatname);
Console.ReadKey();
}
}
}