How to

override Equals method

Published: 24. October 2011 | Updated: 24. October 2011
License: Microsoft Public License (MS-PL)
Categories: Implementations
Tags: C# Design Patterns
Was this snippet helpful for you? YESYES / NONO
public class MyClass
{
    public int Number { get; set; }
    public string Value { get; set; }

    public override bool Equals(object obj)
    {
        if (obj == null || GetType() != obj.GetType()) return false;

        var myClass = (MyClass)obj;
        return (Number == myClass.Number) && (Value == myClass.Value);
    }
}
Send us feedback about this snippet »



Related Snippets: