public static void Main()
var s1 = new Student(new Name("A"));
var s2 = new Student(new Name("A"));
Console.WriteLine(s1.Equals(s2).ToString());
var s3 = new Student(new Name("A"));
Console.WriteLine(s3.Equals(s4).ToString());
public class Student : IEquatable<Student>
public Name Name { get; }
public Student(Name name) => Name = name;
public bool Equals(Student other)
if (ReferenceEquals(this, other))
if (ReferenceEquals(other, null))
return Name.Equals(other.Name);
public class Name : IEquatable<Name>
public string First { get; }
public Name(string first) => First = first;
public bool Equals(Name other)
if (ReferenceEquals(this, other))
if (ReferenceEquals(other, null))
return First == other.First;