I have a class Program
which have an object of class c2
as shown in an example below
class c2{
public string Name;
public int RollNo;
public c2(string Name , int RollNo){
this.Name = Name;
this.RollNo = RollNo;
}
private c2 obj1;
public c2 obj{
get
{
return obj1;
}
set{
obj1=value;
}
}
public void show(){
Console.WriteLine(""+obj1.Name+" "+obj1.RollNo);
}
}
public class Program
{
public static void Main(string[] args)
{
//Your code goes here
c2 objNew = new c2("Test",12);
objNew.obj = objNew;
objNew.show();
}
}
OUTPUT:
Test 12
In the above code class c2
has a private reference obj1
and which is get
set
by an object obj from class program
.How value is assigned to obj and obj1 as they are not physically existed as memory is not assigned to them with the help of new
operator.