public class Person : IEquatable<Person>
{
public string Name { get; init; }
public int Age { get; init; }
public Person(string name, int age)
{
Name = name;
Age = age;
}
public bool Equals(Person? other) =>
other is not null &&
Name == other.Name &&
Age == other.Age;
public override bool Equals(object? obj) =>
Equals(obj as Person);
public override int GetHashCode() =>
HashCode.Combine(Name, Age);
public override string ToString() =>
$"Person {{ Name = {Name}, Age = {Age} }}";
public void Deconstruct(out string name, out int age)
{
name = Name;
age = Age;
}
public static bool operator ==(Person a, Person b) => a.Equals(b);
public static bool operator !=(Person a, Person b) => !a.Equals(b);
}
public class Person : IEquatable<Person>
{
public string Name { get; init; }
public int Age { get; init; }
public Person(string name, int age)
{
Name = name;
Age = age;
}
public bool Equals(Person? other) =>
other is not null &&
Name == other.Name &&
Age == other.Age;
public override bool Equals(object? obj) =>
Equals(obj as Person);
public override int GetHashCode() =>
HashCode.Combine(Name, Age);
public override string ToString() =>
$"Person {{ Name = {Name}, Age = {Age} }}";
public void Deconstruct(out string name, out int age)
{
name = Name;
age = Age;
}
public static bool operator ==(Person a, Person b) => a.Equals(b);
public static bool operator !=(Person a, Person b) => !a.Equals(b);
}