I am trying to compare 2 objects with properties and child properties. The below code always return false even if object values are matching. What is the best option to compare in this case?
Student a = new Student();
a.Name = "john";
a.Address ="CA";
//a.StudDetails.Location = "LA";
//a.StudDetails.Study = "MBA";
//a.StudDetails.Friends = new string[] { "X", "Y"};
Student b = new Student();
b.Name = "john";
b.Address = "CA";
//b.StudDetails.Location = "LA";
//b.StudDetails.Study = "MBA";
//b.StudDetails.Friends = new string[] { "X", "Y"};
bool x = Equals(a, b);
if (x)
{
Console.WriteLine("matched");
}
else
{
Console.WriteLine("Not Matched");
}
public class Student
{
public string Name;
public Details StudDetails;
public string Address;
}
public class Details
{
public string Study;
public string Location;
public string[] Friends;
}