
@Kasani007 Sir, there is no difference. Because, in both the case we are assigning the
studentDomainObject object to
std object. So both the objects are pointing to the same memory block as they are reference types.
So if we write, the output will be same
studentDomainObject.Age=10;
studentDomainObject.Name="test";
Student std=new Student();
std=studentDomainObject;
Console.WriteLine("studentDomainObject.Age = {0},studentDomainObject.Name ={1} ", studentDomainObject.Age,studentDomainObject.Name);
Console.WriteLine("std.Age = {0},std.Name ={1} ", std.Age,std.Name);
Output
-------
studentDomainObject.Age = 10 ,studentDomainObject.Name=test
std.Age = 10 ,std.Name=test
OR
studentDomainObject.Age=10;
studentDomainObject.Name="test";
Student std=studentDomainObject;
Console.WriteLine("studentDomainObject.Age = {0},studentDomainObject.Name ={1} ", studentDomainObject.Age,studentDomainObject.Name);
Console.WriteLine("std.Age = {0},std.Name ={1} ", std.Age,std.Name);
Output
-------
studentDomainObject.Age = 10 ,studentDomainObject.Name=test
std.Age = 10 ,std.Name=test
Note:~ If however, you want to make std a completely different entity from studentDomainObject, you need to do the same by implementing the
IClonable interface (though not recommended by MS Team
https://msdn.microsoft.com/en-us/library/system.icloneable(v=vs.110).aspx )
or by using a
copy constructor .
Hope that helps.
--
Thanks & Regards,
RNA Team
Kasani007, if this helps please login to Mark As Answer. | Alert Moderator