{"id":905,"date":"2009-09-21T17:25:56","date_gmt":"2009-09-21T16:25:56","guid":{"rendered":"http:\/\/soci.hu\/blog\/?p=905"},"modified":"2009-09-21T17:32:16","modified_gmt":"2009-09-21T16:32:16","slug":"mire-valo-az-iequatable","status":"publish","type":"post","link":"https:\/\/soci.hu\/blog\/index.php\/2009\/09\/21\/mire-valo-az-iequatable\/","title":{"rendered":"Mire val\u00f3 az IEquatable<T>?"},"content":{"rendered":"<p>Ha <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/6sh2ey19.aspx\">value type-ot \u00edrsz<\/a>, \u00e9s azon gyors, boxol\u00e1s n\u00e9lk\u00fcli egyenl\u0151s\u00e9gvizsg\u00e1latot akarsz csin\u00e1lni, akkor implement\u00e1ld ezt az interf\u00e9szt.<br \/>\nM\u00e1sk\u00e9pp az object.Equals fut le, ami miatt boxolni kell. Hasonl\u00f3 a helyzet az IComparable<T>-lel is.<br \/>\n\u00c9rdemes megn\u00e9zni debuggerben, mikor-mi fut le, ha implement\u00e1ljuk az interf\u00e9szt, \u00e9s ha kikommentezz\u00fck az implement\u00e1ci\u00f3t:<\/p>\n<p>using System;<br \/>\nusing System.Collections.Generic;<\/p>\n<p>internal struct MyStruct : IEquatable<MyStruct><br \/>\n{<br \/>\n    public MyStruct(int a)<br \/>\n    {<br \/>\n        this.a = a;<br \/>\n    }<\/p>\n<p>    private readonly int a;<\/p>\n<p>    public override bool Equals(object obj)<br \/>\n    {<br \/>\n        return base.Equals(obj);<br \/>\n    }<br \/>\n    public override int GetHashCode()<br \/>\n    {<br \/>\n        return base.GetHashCode();<br \/>\n    }<\/p>\n<p>    #region IEquatable<MyStruct> Members<\/p>\n<p>    public bool Equals(MyStruct other)<br \/>\n    {<br \/>\n        return other.a == a;<br \/>\n    }<\/p>\n<p>    #endregion<br \/>\n}<br \/>\nclass Program<br \/>\n{<br \/>\n    static void Main()<br \/>\n    {<br \/>\n        List<MyStruct> l = new List<MyStruct> {new MyStruct(33)};<br \/>\n        l.Contains(new MyStruct(22));<br \/>\n    }<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ha value type-ot \u00edrsz, \u00e9s azon gyors, boxol\u00e1s n\u00e9lk\u00fcli egyenl\u0151s\u00e9gvizsg\u00e1latot akarsz csin\u00e1lni, akkor implement\u00e1ld ezt az interf\u00e9szt. M\u00e1sk\u00e9pp az object.Equals fut le,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,10,4],"tags":[],"class_list":["post-905","post","type-post","status-publish","format-standard","hentry","category-net","category-c","category-szakmai-elet"],"_links":{"self":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=905"}],"version-history":[{"count":5,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/905\/revisions"}],"predecessor-version":[{"id":910,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/905\/revisions\/910"}],"wp:attachment":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}