If we define any input parameter as “ref”, we basically mark it as reference variable. Hence changing value of it inside child method will reflect change in parent method as well.
namespace Learn{ public class Demo { public int Id { get; set; } } public class Consume { Demo d1 = new Demo(); public void Change(ref Demo d1) { d1.Id = 3; Console.WriteLine(d1.Id); } } class Program { static void Main(string[] args) { Demo d1 = new Demo(); d1.Id = 1; Consume c1 = new Consume(); c1.Change(ref d1); Console.WriteLine(d1.Id); } }}
If this is the program we need. Then object property will retain its value outside the method.