i have used ref in the following way. so when a new object is created in the 5th method does access go all the way to the original emp in the main method and create a new object there? if yes is there a way that i implement the same functionality without so many iterations i.e., it should create a new object in the 5th method itself and the change should be reflected in the main methods' emp too?
public static void Main(string[] args)
{
Employee emp=new Employee();
emp.id=10;
Program p=new Program();
p.Method1(ref emp);
Console.WriteLine(emp.id);
Console.ReadKey();
}
public void Method1(ref Employee emp)
{
Method2(ref emp);
}
public void Method2(ref Employee emp)
{
Method3(ref emp);
}
public void Method3(ref Employee emp)
{
Method4(ref emp);
}
public void Method4(ref Employee emp)
{
Method5(ref emp);
}
public void Method5(ref Employee emp)
{
emp=new Employee();
emp.id=20;
}