[{"data":1,"prerenderedAt":2020},["ShallowReactive",2],{"blog:2005:automaticcomparisonoperatoroverloadingincsharp":3,"blogMore-Development":1688,"comments-automaticcomparisonoperatoroverloadingincsharp":1701},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":11,"tags":12,"excerpt":15,"body":35,"_type":1680,"_id":1681,"_source":1682,"_file":1683,"_stem":1684,"_extension":1685,"url":1686,"wordCount":1687,"minutes":146,"commentCount":114},"/blog/2005/automaticcomparisonoperatoroverloadingincsharp","2005",false,"en","Automatic comparison operator overloading in C#","Abhinaba has blogged on the painful C# operator overloading experience.","2005-10-11T09:12:00+00:00","Development",[13,14],".NET","C#",{"type":16,"children":17},"root",[18,30],{"type":19,"tag":20,"props":21,"children":22},"element","p",{},[23,26,28],{"type":24,"value":25},"text","Abhinaba has blogged on the ",{"type":24,"value":27},"painful C# operator overloading",{"type":24,"value":29}," experience.",{"type":19,"tag":20,"props":31,"children":32},{},[33],{"type":24,"value":34},"The basic problem that is if you want to overload one, you soon end up many of the tests including == != \u003C \u003C= > >= Equals, Compare and probably CompareTo via IComparable when it turns out one function can provide everything needed in general use.",{"type":16,"children":36,"toc":1678},[37,50,54,79,82,99,1210,1215,1644,1649,1663,1672],{"type":19,"tag":20,"props":38,"children":39},{},[40,41,49],{"type":24,"value":25},{"type":19,"tag":42,"props":43,"children":47},"a",{"href":44,"rel":45},"https://blogs.msdn.com/abhinaba/archive/2005/10/11/479537.aspx",[46],"nofollow",[48],{"type":24,"value":27},{"type":24,"value":29},{"type":19,"tag":20,"props":51,"children":52},{},[53],{"type":24,"value":34},{"type":19,"tag":55,"props":56,"children":57},"blockquote",{},[58,76],{"type":19,"tag":20,"props":59,"children":60},{},[61,63],{"type":24,"value":62},"GitHub has the ",{"type":19,"tag":42,"props":64,"children":66},{"href":65},"https://github.com/damieng/DamienGKit/blob/master/CSharp/DamienG.Library/System/AutoOperators.cs",[67,69],{"type":24,"value":68},"latest version of ",{"type":19,"tag":70,"props":71,"children":73},"code",{"className":72},[],[74],{"type":24,"value":75},"AutoOperators",{"type":19,"tag":42,"props":77,"children":78},{"href":65},[],{"type":19,"tag":42,"props":80,"children":81},{"href":65},[],{"type":19,"tag":20,"props":83,"children":84},{},[85,90,97],{"type":19,"tag":42,"props":86,"children":87},{"href":65},[88],{"type":24,"value":89},"Ruby already has this with the ",{"type":19,"tag":42,"props":91,"children":94},{"href":92,"rel":93},"https://www.rubycentral.com/ref/ref_c_array.html#_lt_eq_gt",[46],[95],{"type":24,"value":96},"\u003C=> operator, sometimes known as a SpaceShipOperator",{"type":24,"value":98}," and this got me thinking resulting in the following little class:",{"type":19,"tag":100,"props":101,"children":106},"pre",{"className":102,"code":103,"language":104,"meta":105,"style":105},"language-csharp shiki shiki-themes everforest-light dracula","using System;\n\n/// AutoOperators provides a base class where all the standard operators are overridden and\n/// wired up via the subclass's implementation of IComparable.CompareTo.\npublic abstract class AutoOperators : IComparable {\n  public static bool operator \u003C (AutoOperators obj1, AutoOperators obj2) {\n    return Compare(obj1, obj2) \u003C 0;\n  }\n  public static bool operator > (AutoOperators obj1, AutoOperators obj2) {\n    return Compare(obj1, obj2) > 0;\n  }\n  public static bool operator == (AutoOperators obj1, AutoOperators obj2) {\n    return Compare(obj1, obj2) == 0;\n  }\n  public static bool operator != (AutoOperators obj1, AutoOperators obj2) {\n    return Compare(obj1, obj2) != 0;\n  }\n  public static bool operator \u003C= (AutoOperators obj1, AutoOperators obj2) {\n    return Compare(obj1, obj2) \u003C= 0;\n  }\n  public static bool operator >= (AutoOperators obj1, AutoOperators obj2) {\n    return Compare(obj1, obj2) >= 0;\n  }\n\n  public static int Compare(AutoOperators obj1, AutoOperators obj2) {\n    if (Object.ReferenceEquals(obj1, obj2)) return 0;\n    if ((object)obj1 == null) return -1;\n    if ((object)obj2 == null) return 1;\n    return obj1.CompareTo(obj2);\n  }\n\n  public abstract int CompareTo(object obj);\n  public abstract override int GetHashCode();\n\n  public override bool Equals(object obj) {\n    if (!(obj is AutoOperators)) return false;\n    return this == (AutoOperators) obj;\n  }\n}\n","csharp","",[107],{"type":19,"tag":70,"props":108,"children":109},{"__ignoreMap":105},[110,134,144,154,163,205,270,304,313,366,395,403,456,485,493,546,575,583,636,665,673,726,755,763,771,821,858,913,959,982,990,998,1037,1068,1076,1113,1162,1193,1201],{"type":19,"tag":111,"props":112,"children":115},"span",{"class":113,"line":114},"line",1,[116,122,128],{"type":19,"tag":111,"props":117,"children":119},{"style":118},"--shiki-default:#F85552;--shiki-dark:#FF79C6",[120],{"type":24,"value":121},"using",{"type":19,"tag":111,"props":123,"children":125},{"style":124},"--shiki-default:#DF69BA;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[126],{"type":24,"value":127}," System",{"type":19,"tag":111,"props":129,"children":131},{"style":130},"--shiki-default:#5C6A72;--shiki-dark:#F8F8F2",[132],{"type":24,"value":133},";\n",{"type":19,"tag":111,"props":135,"children":137},{"class":113,"line":136},2,[138],{"type":19,"tag":111,"props":139,"children":141},{"emptyLinePlaceholder":140},true,[142],{"type":24,"value":143},"\n",{"type":19,"tag":111,"props":145,"children":147},{"class":113,"line":146},3,[148],{"type":19,"tag":111,"props":149,"children":151},{"style":150},"--shiki-default:#939F91;--shiki-default-font-style:italic;--shiki-dark:#6272A4;--shiki-dark-font-style:inherit",[152],{"type":24,"value":153},"/// AutoOperators provides a base class where all the standard operators are overridden and\n",{"type":19,"tag":111,"props":155,"children":157},{"class":113,"line":156},4,[158],{"type":19,"tag":111,"props":159,"children":160},{"style":150},[161],{"type":24,"value":162},"/// wired up via the subclass's implementation of IComparable.CompareTo.\n",{"type":19,"tag":111,"props":164,"children":166},{"class":113,"line":165},5,[167,173,178,183,189,194,200],{"type":19,"tag":111,"props":168,"children":170},{"style":169},"--shiki-default:#F57D26;--shiki-dark:#FF79C6",[171],{"type":24,"value":172},"public",{"type":19,"tag":111,"props":174,"children":175},{"style":169},[176],{"type":24,"value":177}," abstract",{"type":19,"tag":111,"props":179,"children":180},{"style":118},[181],{"type":24,"value":182}," class",{"type":19,"tag":111,"props":184,"children":186},{"style":185},"--shiki-default:#3A94C5;--shiki-dark:#8BE9FD",[187],{"type":24,"value":188}," AutoOperators",{"type":19,"tag":111,"props":190,"children":191},{"style":130},[192],{"type":24,"value":193}," : ",{"type":19,"tag":111,"props":195,"children":197},{"style":196},"--shiki-default:#3A94C5;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[198],{"type":24,"value":199},"IComparable",{"type":19,"tag":111,"props":201,"children":202},{"style":130},[203],{"type":24,"value":204}," {\n",{"type":19,"tag":111,"props":206,"children":208},{"class":113,"line":207},6,[209,214,219,225,230,236,241,245,251,256,260,265],{"type":19,"tag":111,"props":210,"children":211},{"style":169},[212],{"type":24,"value":213},"  public",{"type":19,"tag":111,"props":215,"children":216},{"style":169},[217],{"type":24,"value":218}," static",{"type":19,"tag":111,"props":220,"children":222},{"style":221},"--shiki-default:#3A94C5;--shiki-dark:#FF79C6",[223],{"type":24,"value":224}," bool",{"type":19,"tag":111,"props":226,"children":227},{"style":221},[228],{"type":24,"value":229}," operator",{"type":19,"tag":111,"props":231,"children":233},{"style":232},"--shiki-default:#8DA101;--shiki-dark:#50FA7B",[234],{"type":24,"value":235}," \u003C",{"type":19,"tag":111,"props":237,"children":238},{"style":130},[239],{"type":24,"value":240}," (",{"type":19,"tag":111,"props":242,"children":243},{"style":196},[244],{"type":24,"value":75},{"type":19,"tag":111,"props":246,"children":248},{"style":247},"--shiki-default:#5C6A72;--shiki-default-font-style:inherit;--shiki-dark:#FFB86C;--shiki-dark-font-style:italic",[249],{"type":24,"value":250}," obj1",{"type":19,"tag":111,"props":252,"children":253},{"style":130},[254],{"type":24,"value":255},", ",{"type":19,"tag":111,"props":257,"children":258},{"style":196},[259],{"type":24,"value":75},{"type":19,"tag":111,"props":261,"children":262},{"style":247},[263],{"type":24,"value":264}," obj2",{"type":19,"tag":111,"props":266,"children":267},{"style":130},[268],{"type":24,"value":269},") {\n",{"type":19,"tag":111,"props":271,"children":273},{"class":113,"line":272},7,[274,279,284,289,294,300],{"type":19,"tag":111,"props":275,"children":276},{"style":118},[277],{"type":24,"value":278},"    return",{"type":19,"tag":111,"props":280,"children":281},{"style":232},[282],{"type":24,"value":283}," Compare",{"type":19,"tag":111,"props":285,"children":286},{"style":130},[287],{"type":24,"value":288},"(obj1, obj2) ",{"type":19,"tag":111,"props":290,"children":291},{"style":169},[292],{"type":24,"value":293},"\u003C",{"type":19,"tag":111,"props":295,"children":297},{"style":296},"--shiki-default:#DF69BA;--shiki-dark:#BD93F9",[298],{"type":24,"value":299}," 0",{"type":19,"tag":111,"props":301,"children":302},{"style":130},[303],{"type":24,"value":133},{"type":19,"tag":111,"props":305,"children":307},{"class":113,"line":306},8,[308],{"type":19,"tag":111,"props":309,"children":310},{"style":130},[311],{"type":24,"value":312},"  }\n",{"type":19,"tag":111,"props":314,"children":316},{"class":113,"line":315},9,[317,321,325,329,333,338,342,346,350,354,358,362],{"type":19,"tag":111,"props":318,"children":319},{"style":169},[320],{"type":24,"value":213},{"type":19,"tag":111,"props":322,"children":323},{"style":169},[324],{"type":24,"value":218},{"type":19,"tag":111,"props":326,"children":327},{"style":221},[328],{"type":24,"value":224},{"type":19,"tag":111,"props":330,"children":331},{"style":221},[332],{"type":24,"value":229},{"type":19,"tag":111,"props":334,"children":335},{"style":232},[336],{"type":24,"value":337}," >",{"type":19,"tag":111,"props":339,"children":340},{"style":130},[341],{"type":24,"value":240},{"type":19,"tag":111,"props":343,"children":344},{"style":196},[345],{"type":24,"value":75},{"type":19,"tag":111,"props":347,"children":348},{"style":247},[349],{"type":24,"value":250},{"type":19,"tag":111,"props":351,"children":352},{"style":130},[353],{"type":24,"value":255},{"type":19,"tag":111,"props":355,"children":356},{"style":196},[357],{"type":24,"value":75},{"type":19,"tag":111,"props":359,"children":360},{"style":247},[361],{"type":24,"value":264},{"type":19,"tag":111,"props":363,"children":364},{"style":130},[365],{"type":24,"value":269},{"type":19,"tag":111,"props":367,"children":369},{"class":113,"line":368},10,[370,374,378,382,387,391],{"type":19,"tag":111,"props":371,"children":372},{"style":118},[373],{"type":24,"value":278},{"type":19,"tag":111,"props":375,"children":376},{"style":232},[377],{"type":24,"value":283},{"type":19,"tag":111,"props":379,"children":380},{"style":130},[381],{"type":24,"value":288},{"type":19,"tag":111,"props":383,"children":384},{"style":169},[385],{"type":24,"value":386},">",{"type":19,"tag":111,"props":388,"children":389},{"style":296},[390],{"type":24,"value":299},{"type":19,"tag":111,"props":392,"children":393},{"style":130},[394],{"type":24,"value":133},{"type":19,"tag":111,"props":396,"children":398},{"class":113,"line":397},11,[399],{"type":19,"tag":111,"props":400,"children":401},{"style":130},[402],{"type":24,"value":312},{"type":19,"tag":111,"props":404,"children":406},{"class":113,"line":405},12,[407,411,415,419,423,428,432,436,440,444,448,452],{"type":19,"tag":111,"props":408,"children":409},{"style":169},[410],{"type":24,"value":213},{"type":19,"tag":111,"props":412,"children":413},{"style":169},[414],{"type":24,"value":218},{"type":19,"tag":111,"props":416,"children":417},{"style":221},[418],{"type":24,"value":224},{"type":19,"tag":111,"props":420,"children":421},{"style":221},[422],{"type":24,"value":229},{"type":19,"tag":111,"props":424,"children":425},{"style":232},[426],{"type":24,"value":427}," ==",{"type":19,"tag":111,"props":429,"children":430},{"style":130},[431],{"type":24,"value":240},{"type":19,"tag":111,"props":433,"children":434},{"style":196},[435],{"type":24,"value":75},{"type":19,"tag":111,"props":437,"children":438},{"style":247},[439],{"type":24,"value":250},{"type":19,"tag":111,"props":441,"children":442},{"style":130},[443],{"type":24,"value":255},{"type":19,"tag":111,"props":445,"children":446},{"style":196},[447],{"type":24,"value":75},{"type":19,"tag":111,"props":449,"children":450},{"style":247},[451],{"type":24,"value":264},{"type":19,"tag":111,"props":453,"children":454},{"style":130},[455],{"type":24,"value":269},{"type":19,"tag":111,"props":457,"children":459},{"class":113,"line":458},13,[460,464,468,472,477,481],{"type":19,"tag":111,"props":461,"children":462},{"style":118},[463],{"type":24,"value":278},{"type":19,"tag":111,"props":465,"children":466},{"style":232},[467],{"type":24,"value":283},{"type":19,"tag":111,"props":469,"children":470},{"style":130},[471],{"type":24,"value":288},{"type":19,"tag":111,"props":473,"children":474},{"style":169},[475],{"type":24,"value":476},"==",{"type":19,"tag":111,"props":478,"children":479},{"style":296},[480],{"type":24,"value":299},{"type":19,"tag":111,"props":482,"children":483},{"style":130},[484],{"type":24,"value":133},{"type":19,"tag":111,"props":486,"children":488},{"class":113,"line":487},14,[489],{"type":19,"tag":111,"props":490,"children":491},{"style":130},[492],{"type":24,"value":312},{"type":19,"tag":111,"props":494,"children":496},{"class":113,"line":495},15,[497,501,505,509,513,518,522,526,530,534,538,542],{"type":19,"tag":111,"props":498,"children":499},{"style":169},[500],{"type":24,"value":213},{"type":19,"tag":111,"props":502,"children":503},{"style":169},[504],{"type":24,"value":218},{"type":19,"tag":111,"props":506,"children":507},{"style":221},[508],{"type":24,"value":224},{"type":19,"tag":111,"props":510,"children":511},{"style":221},[512],{"type":24,"value":229},{"type":19,"tag":111,"props":514,"children":515},{"style":232},[516],{"type":24,"value":517}," !=",{"type":19,"tag":111,"props":519,"children":520},{"style":130},[521],{"type":24,"value":240},{"type":19,"tag":111,"props":523,"children":524},{"style":196},[525],{"type":24,"value":75},{"type":19,"tag":111,"props":527,"children":528},{"style":247},[529],{"type":24,"value":250},{"type":19,"tag":111,"props":531,"children":532},{"style":130},[533],{"type":24,"value":255},{"type":19,"tag":111,"props":535,"children":536},{"style":196},[537],{"type":24,"value":75},{"type":19,"tag":111,"props":539,"children":540},{"style":247},[541],{"type":24,"value":264},{"type":19,"tag":111,"props":543,"children":544},{"style":130},[545],{"type":24,"value":269},{"type":19,"tag":111,"props":547,"children":549},{"class":113,"line":548},16,[550,554,558,562,567,571],{"type":19,"tag":111,"props":551,"children":552},{"style":118},[553],{"type":24,"value":278},{"type":19,"tag":111,"props":555,"children":556},{"style":232},[557],{"type":24,"value":283},{"type":19,"tag":111,"props":559,"children":560},{"style":130},[561],{"type":24,"value":288},{"type":19,"tag":111,"props":563,"children":564},{"style":169},[565],{"type":24,"value":566},"!=",{"type":19,"tag":111,"props":568,"children":569},{"style":296},[570],{"type":24,"value":299},{"type":19,"tag":111,"props":572,"children":573},{"style":130},[574],{"type":24,"value":133},{"type":19,"tag":111,"props":576,"children":578},{"class":113,"line":577},17,[579],{"type":19,"tag":111,"props":580,"children":581},{"style":130},[582],{"type":24,"value":312},{"type":19,"tag":111,"props":584,"children":586},{"class":113,"line":585},18,[587,591,595,599,603,608,612,616,620,624,628,632],{"type":19,"tag":111,"props":588,"children":589},{"style":169},[590],{"type":24,"value":213},{"type":19,"tag":111,"props":592,"children":593},{"style":169},[594],{"type":24,"value":218},{"type":19,"tag":111,"props":596,"children":597},{"style":221},[598],{"type":24,"value":224},{"type":19,"tag":111,"props":600,"children":601},{"style":221},[602],{"type":24,"value":229},{"type":19,"tag":111,"props":604,"children":605},{"style":232},[606],{"type":24,"value":607}," \u003C=",{"type":19,"tag":111,"props":609,"children":610},{"style":130},[611],{"type":24,"value":240},{"type":19,"tag":111,"props":613,"children":614},{"style":196},[615],{"type":24,"value":75},{"type":19,"tag":111,"props":617,"children":618},{"style":247},[619],{"type":24,"value":250},{"type":19,"tag":111,"props":621,"children":622},{"style":130},[623],{"type":24,"value":255},{"type":19,"tag":111,"props":625,"children":626},{"style":196},[627],{"type":24,"value":75},{"type":19,"tag":111,"props":629,"children":630},{"style":247},[631],{"type":24,"value":264},{"type":19,"tag":111,"props":633,"children":634},{"style":130},[635],{"type":24,"value":269},{"type":19,"tag":111,"props":637,"children":639},{"class":113,"line":638},19,[640,644,648,652,657,661],{"type":19,"tag":111,"props":641,"children":642},{"style":118},[643],{"type":24,"value":278},{"type":19,"tag":111,"props":645,"children":646},{"style":232},[647],{"type":24,"value":283},{"type":19,"tag":111,"props":649,"children":650},{"style":130},[651],{"type":24,"value":288},{"type":19,"tag":111,"props":653,"children":654},{"style":169},[655],{"type":24,"value":656},"\u003C=",{"type":19,"tag":111,"props":658,"children":659},{"style":296},[660],{"type":24,"value":299},{"type":19,"tag":111,"props":662,"children":663},{"style":130},[664],{"type":24,"value":133},{"type":19,"tag":111,"props":666,"children":668},{"class":113,"line":667},20,[669],{"type":19,"tag":111,"props":670,"children":671},{"style":130},[672],{"type":24,"value":312},{"type":19,"tag":111,"props":674,"children":676},{"class":113,"line":675},21,[677,681,685,689,693,698,702,706,710,714,718,722],{"type":19,"tag":111,"props":678,"children":679},{"style":169},[680],{"type":24,"value":213},{"type":19,"tag":111,"props":682,"children":683},{"style":169},[684],{"type":24,"value":218},{"type":19,"tag":111,"props":686,"children":687},{"style":221},[688],{"type":24,"value":224},{"type":19,"tag":111,"props":690,"children":691},{"style":221},[692],{"type":24,"value":229},{"type":19,"tag":111,"props":694,"children":695},{"style":232},[696],{"type":24,"value":697}," >=",{"type":19,"tag":111,"props":699,"children":700},{"style":130},[701],{"type":24,"value":240},{"type":19,"tag":111,"props":703,"children":704},{"style":196},[705],{"type":24,"value":75},{"type":19,"tag":111,"props":707,"children":708},{"style":247},[709],{"type":24,"value":250},{"type":19,"tag":111,"props":711,"children":712},{"style":130},[713],{"type":24,"value":255},{"type":19,"tag":111,"props":715,"children":716},{"style":196},[717],{"type":24,"value":75},{"type":19,"tag":111,"props":719,"children":720},{"style":247},[721],{"type":24,"value":264},{"type":19,"tag":111,"props":723,"children":724},{"style":130},[725],{"type":24,"value":269},{"type":19,"tag":111,"props":727,"children":729},{"class":113,"line":728},22,[730,734,738,742,747,751],{"type":19,"tag":111,"props":731,"children":732},{"style":118},[733],{"type":24,"value":278},{"type":19,"tag":111,"props":735,"children":736},{"style":232},[737],{"type":24,"value":283},{"type":19,"tag":111,"props":739,"children":740},{"style":130},[741],{"type":24,"value":288},{"type":19,"tag":111,"props":743,"children":744},{"style":169},[745],{"type":24,"value":746},">=",{"type":19,"tag":111,"props":748,"children":749},{"style":296},[750],{"type":24,"value":299},{"type":19,"tag":111,"props":752,"children":753},{"style":130},[754],{"type":24,"value":133},{"type":19,"tag":111,"props":756,"children":758},{"class":113,"line":757},23,[759],{"type":19,"tag":111,"props":760,"children":761},{"style":130},[762],{"type":24,"value":312},{"type":19,"tag":111,"props":764,"children":766},{"class":113,"line":765},24,[767],{"type":19,"tag":111,"props":768,"children":769},{"emptyLinePlaceholder":140},[770],{"type":24,"value":143},{"type":19,"tag":111,"props":772,"children":774},{"class":113,"line":773},25,[775,779,783,788,792,797,801,805,809,813,817],{"type":19,"tag":111,"props":776,"children":777},{"style":169},[778],{"type":24,"value":213},{"type":19,"tag":111,"props":780,"children":781},{"style":169},[782],{"type":24,"value":218},{"type":19,"tag":111,"props":784,"children":785},{"style":221},[786],{"type":24,"value":787}," int",{"type":19,"tag":111,"props":789,"children":790},{"style":232},[791],{"type":24,"value":283},{"type":19,"tag":111,"props":793,"children":794},{"style":130},[795],{"type":24,"value":796},"(",{"type":19,"tag":111,"props":798,"children":799},{"style":196},[800],{"type":24,"value":75},{"type":19,"tag":111,"props":802,"children":803},{"style":247},[804],{"type":24,"value":250},{"type":19,"tag":111,"props":806,"children":807},{"style":130},[808],{"type":24,"value":255},{"type":19,"tag":111,"props":810,"children":811},{"style":196},[812],{"type":24,"value":75},{"type":19,"tag":111,"props":814,"children":815},{"style":247},[816],{"type":24,"value":264},{"type":19,"tag":111,"props":818,"children":819},{"style":130},[820],{"type":24,"value":269},{"type":19,"tag":111,"props":822,"children":824},{"class":113,"line":823},26,[825,830,835,840,845,850,854],{"type":19,"tag":111,"props":826,"children":827},{"style":118},[828],{"type":24,"value":829},"    if",{"type":19,"tag":111,"props":831,"children":832},{"style":130},[833],{"type":24,"value":834}," (Object.",{"type":19,"tag":111,"props":836,"children":837},{"style":232},[838],{"type":24,"value":839},"ReferenceEquals",{"type":19,"tag":111,"props":841,"children":842},{"style":130},[843],{"type":24,"value":844},"(obj1, obj2)) ",{"type":19,"tag":111,"props":846,"children":847},{"style":118},[848],{"type":24,"value":849},"return",{"type":19,"tag":111,"props":851,"children":852},{"style":296},[853],{"type":24,"value":299},{"type":19,"tag":111,"props":855,"children":856},{"style":130},[857],{"type":24,"value":133},{"type":19,"tag":111,"props":859,"children":861},{"class":113,"line":860},27,[862,866,871,876,881,885,890,895,899,904,909],{"type":19,"tag":111,"props":863,"children":864},{"style":118},[865],{"type":24,"value":829},{"type":19,"tag":111,"props":867,"children":868},{"style":130},[869],{"type":24,"value":870}," ((",{"type":19,"tag":111,"props":872,"children":873},{"style":221},[874],{"type":24,"value":875},"object",{"type":19,"tag":111,"props":877,"children":878},{"style":130},[879],{"type":24,"value":880},")obj1 ",{"type":19,"tag":111,"props":882,"children":883},{"style":169},[884],{"type":24,"value":476},{"type":19,"tag":111,"props":886,"children":887},{"style":296},[888],{"type":24,"value":889}," null",{"type":19,"tag":111,"props":891,"children":892},{"style":130},[893],{"type":24,"value":894},") ",{"type":19,"tag":111,"props":896,"children":897},{"style":118},[898],{"type":24,"value":849},{"type":19,"tag":111,"props":900,"children":901},{"style":169},[902],{"type":24,"value":903}," -",{"type":19,"tag":111,"props":905,"children":906},{"style":296},[907],{"type":24,"value":908},"1",{"type":19,"tag":111,"props":910,"children":911},{"style":130},[912],{"type":24,"value":133},{"type":19,"tag":111,"props":914,"children":916},{"class":113,"line":915},28,[917,921,925,929,934,938,942,946,950,955],{"type":19,"tag":111,"props":918,"children":919},{"style":118},[920],{"type":24,"value":829},{"type":19,"tag":111,"props":922,"children":923},{"style":130},[924],{"type":24,"value":870},{"type":19,"tag":111,"props":926,"children":927},{"style":221},[928],{"type":24,"value":875},{"type":19,"tag":111,"props":930,"children":931},{"style":130},[932],{"type":24,"value":933},")obj2 ",{"type":19,"tag":111,"props":935,"children":936},{"style":169},[937],{"type":24,"value":476},{"type":19,"tag":111,"props":939,"children":940},{"style":296},[941],{"type":24,"value":889},{"type":19,"tag":111,"props":943,"children":944},{"style":130},[945],{"type":24,"value":894},{"type":19,"tag":111,"props":947,"children":948},{"style":118},[949],{"type":24,"value":849},{"type":19,"tag":111,"props":951,"children":952},{"style":296},[953],{"type":24,"value":954}," 1",{"type":19,"tag":111,"props":956,"children":957},{"style":130},[958],{"type":24,"value":133},{"type":19,"tag":111,"props":960,"children":962},{"class":113,"line":961},29,[963,967,972,977],{"type":19,"tag":111,"props":964,"children":965},{"style":118},[966],{"type":24,"value":278},{"type":19,"tag":111,"props":968,"children":969},{"style":130},[970],{"type":24,"value":971}," obj1.",{"type":19,"tag":111,"props":973,"children":974},{"style":232},[975],{"type":24,"value":976},"CompareTo",{"type":19,"tag":111,"props":978,"children":979},{"style":130},[980],{"type":24,"value":981},"(obj2);\n",{"type":19,"tag":111,"props":983,"children":985},{"class":113,"line":984},30,[986],{"type":19,"tag":111,"props":987,"children":988},{"style":130},[989],{"type":24,"value":312},{"type":19,"tag":111,"props":991,"children":993},{"class":113,"line":992},31,[994],{"type":19,"tag":111,"props":995,"children":996},{"emptyLinePlaceholder":140},[997],{"type":24,"value":143},{"type":19,"tag":111,"props":999,"children":1001},{"class":113,"line":1000},32,[1002,1006,1010,1014,1019,1023,1027,1032],{"type":19,"tag":111,"props":1003,"children":1004},{"style":169},[1005],{"type":24,"value":213},{"type":19,"tag":111,"props":1007,"children":1008},{"style":169},[1009],{"type":24,"value":177},{"type":19,"tag":111,"props":1011,"children":1012},{"style":221},[1013],{"type":24,"value":787},{"type":19,"tag":111,"props":1015,"children":1016},{"style":232},[1017],{"type":24,"value":1018}," CompareTo",{"type":19,"tag":111,"props":1020,"children":1021},{"style":130},[1022],{"type":24,"value":796},{"type":19,"tag":111,"props":1024,"children":1025},{"style":221},[1026],{"type":24,"value":875},{"type":19,"tag":111,"props":1028,"children":1029},{"style":247},[1030],{"type":24,"value":1031}," obj",{"type":19,"tag":111,"props":1033,"children":1034},{"style":130},[1035],{"type":24,"value":1036},");\n",{"type":19,"tag":111,"props":1038,"children":1040},{"class":113,"line":1039},33,[1041,1045,1049,1054,1058,1063],{"type":19,"tag":111,"props":1042,"children":1043},{"style":169},[1044],{"type":24,"value":213},{"type":19,"tag":111,"props":1046,"children":1047},{"style":169},[1048],{"type":24,"value":177},{"type":19,"tag":111,"props":1050,"children":1051},{"style":169},[1052],{"type":24,"value":1053}," override",{"type":19,"tag":111,"props":1055,"children":1056},{"style":221},[1057],{"type":24,"value":787},{"type":19,"tag":111,"props":1059,"children":1060},{"style":232},[1061],{"type":24,"value":1062}," GetHashCode",{"type":19,"tag":111,"props":1064,"children":1065},{"style":130},[1066],{"type":24,"value":1067},"();\n",{"type":19,"tag":111,"props":1069,"children":1071},{"class":113,"line":1070},34,[1072],{"type":19,"tag":111,"props":1073,"children":1074},{"emptyLinePlaceholder":140},[1075],{"type":24,"value":143},{"type":19,"tag":111,"props":1077,"children":1079},{"class":113,"line":1078},35,[1080,1084,1088,1092,1097,1101,1105,1109],{"type":19,"tag":111,"props":1081,"children":1082},{"style":169},[1083],{"type":24,"value":213},{"type":19,"tag":111,"props":1085,"children":1086},{"style":169},[1087],{"type":24,"value":1053},{"type":19,"tag":111,"props":1089,"children":1090},{"style":221},[1091],{"type":24,"value":224},{"type":19,"tag":111,"props":1093,"children":1094},{"style":232},[1095],{"type":24,"value":1096}," Equals",{"type":19,"tag":111,"props":1098,"children":1099},{"style":130},[1100],{"type":24,"value":796},{"type":19,"tag":111,"props":1102,"children":1103},{"style":221},[1104],{"type":24,"value":875},{"type":19,"tag":111,"props":1106,"children":1107},{"style":247},[1108],{"type":24,"value":1031},{"type":19,"tag":111,"props":1110,"children":1111},{"style":130},[1112],{"type":24,"value":269},{"type":19,"tag":111,"props":1114,"children":1116},{"class":113,"line":1115},36,[1117,1121,1125,1130,1135,1140,1144,1149,1153,1158],{"type":19,"tag":111,"props":1118,"children":1119},{"style":118},[1120],{"type":24,"value":829},{"type":19,"tag":111,"props":1122,"children":1123},{"style":130},[1124],{"type":24,"value":240},{"type":19,"tag":111,"props":1126,"children":1127},{"style":169},[1128],{"type":24,"value":1129},"!",{"type":19,"tag":111,"props":1131,"children":1132},{"style":130},[1133],{"type":24,"value":1134},"(obj ",{"type":19,"tag":111,"props":1136,"children":1137},{"style":118},[1138],{"type":24,"value":1139},"is",{"type":19,"tag":111,"props":1141,"children":1142},{"style":196},[1143],{"type":24,"value":188},{"type":19,"tag":111,"props":1145,"children":1146},{"style":130},[1147],{"type":24,"value":1148},")) ",{"type":19,"tag":111,"props":1150,"children":1151},{"style":118},[1152],{"type":24,"value":849},{"type":19,"tag":111,"props":1154,"children":1155},{"style":296},[1156],{"type":24,"value":1157}," false",{"type":19,"tag":111,"props":1159,"children":1160},{"style":130},[1161],{"type":24,"value":133},{"type":19,"tag":111,"props":1163,"children":1165},{"class":113,"line":1164},37,[1166,1170,1176,1180,1184,1188],{"type":19,"tag":111,"props":1167,"children":1168},{"style":118},[1169],{"type":24,"value":278},{"type":19,"tag":111,"props":1171,"children":1173},{"style":1172},"--shiki-default:#DF69BA;--shiki-default-font-style:inherit;--shiki-dark:#BD93F9;--shiki-dark-font-style:italic",[1174],{"type":24,"value":1175}," this",{"type":19,"tag":111,"props":1177,"children":1178},{"style":169},[1179],{"type":24,"value":427},{"type":19,"tag":111,"props":1181,"children":1182},{"style":130},[1183],{"type":24,"value":240},{"type":19,"tag":111,"props":1185,"children":1186},{"style":196},[1187],{"type":24,"value":75},{"type":19,"tag":111,"props":1189,"children":1190},{"style":130},[1191],{"type":24,"value":1192},") obj;\n",{"type":19,"tag":111,"props":1194,"children":1196},{"class":113,"line":1195},38,[1197],{"type":19,"tag":111,"props":1198,"children":1199},{"style":130},[1200],{"type":24,"value":312},{"type":19,"tag":111,"props":1202,"children":1204},{"class":113,"line":1203},39,[1205],{"type":19,"tag":111,"props":1206,"children":1207},{"style":130},[1208],{"type":24,"value":1209},"}\n",{"type":19,"tag":20,"props":1211,"children":1212},{},[1213],{"type":24,"value":1214},"And then to use it simply inherit from it and implement GetHashCode and CompareTo, e.g.",{"type":19,"tag":100,"props":1216,"children":1218},{"className":102,"code":1217,"language":104,"meta":105,"style":105},"using System;\n\npublic class SampleClass : AutoOperators {\n  private int testValue = 0;\n\n  public SampleClass(int initialTestValue) {\n    testValue = initialTestValue;\n  }\n\n  public int TestValue {\n    get { return testValue; }\n    set { testValue = value; }\n  }\n\n  public override int CompareTo(object obj) {\n    if (obj is SampleClass)\n       return TestValue.CompareTo(((SampleClass) obj).TestValue);\n    else\n       return -1;\n  }\n\n  public override int GetHashCode() {\n    return TestValue.GetHashCode();\n  }\n}\n",[1219],{"type":19,"tag":70,"props":1220,"children":1221},{"__ignoreMap":105},[1222,1237,1244,1272,1302,1309,1338,1355,1362,1369,1385,1407,1429,1436,1443,1478,1503,1545,1553,1572,1579,1586,1610,1630,1637],{"type":19,"tag":111,"props":1223,"children":1224},{"class":113,"line":114},[1225,1229,1233],{"type":19,"tag":111,"props":1226,"children":1227},{"style":118},[1228],{"type":24,"value":121},{"type":19,"tag":111,"props":1230,"children":1231},{"style":124},[1232],{"type":24,"value":127},{"type":19,"tag":111,"props":1234,"children":1235},{"style":130},[1236],{"type":24,"value":133},{"type":19,"tag":111,"props":1238,"children":1239},{"class":113,"line":136},[1240],{"type":19,"tag":111,"props":1241,"children":1242},{"emptyLinePlaceholder":140},[1243],{"type":24,"value":143},{"type":19,"tag":111,"props":1245,"children":1246},{"class":113,"line":146},[1247,1251,1255,1260,1264,1268],{"type":19,"tag":111,"props":1248,"children":1249},{"style":169},[1250],{"type":24,"value":172},{"type":19,"tag":111,"props":1252,"children":1253},{"style":118},[1254],{"type":24,"value":182},{"type":19,"tag":111,"props":1256,"children":1257},{"style":185},[1258],{"type":24,"value":1259}," SampleClass",{"type":19,"tag":111,"props":1261,"children":1262},{"style":130},[1263],{"type":24,"value":193},{"type":19,"tag":111,"props":1265,"children":1266},{"style":196},[1267],{"type":24,"value":75},{"type":19,"tag":111,"props":1269,"children":1270},{"style":130},[1271],{"type":24,"value":204},{"type":19,"tag":111,"props":1273,"children":1274},{"class":113,"line":156},[1275,1280,1284,1289,1294,1298],{"type":19,"tag":111,"props":1276,"children":1277},{"style":169},[1278],{"type":24,"value":1279},"  private",{"type":19,"tag":111,"props":1281,"children":1282},{"style":221},[1283],{"type":24,"value":787},{"type":19,"tag":111,"props":1285,"children":1286},{"style":130},[1287],{"type":24,"value":1288}," testValue ",{"type":19,"tag":111,"props":1290,"children":1291},{"style":169},[1292],{"type":24,"value":1293},"=",{"type":19,"tag":111,"props":1295,"children":1296},{"style":296},[1297],{"type":24,"value":299},{"type":19,"tag":111,"props":1299,"children":1300},{"style":130},[1301],{"type":24,"value":133},{"type":19,"tag":111,"props":1303,"children":1304},{"class":113,"line":165},[1305],{"type":19,"tag":111,"props":1306,"children":1307},{"emptyLinePlaceholder":140},[1308],{"type":24,"value":143},{"type":19,"tag":111,"props":1310,"children":1311},{"class":113,"line":207},[1312,1316,1320,1324,1329,1334],{"type":19,"tag":111,"props":1313,"children":1314},{"style":169},[1315],{"type":24,"value":213},{"type":19,"tag":111,"props":1317,"children":1318},{"style":232},[1319],{"type":24,"value":1259},{"type":19,"tag":111,"props":1321,"children":1322},{"style":130},[1323],{"type":24,"value":796},{"type":19,"tag":111,"props":1325,"children":1326},{"style":221},[1327],{"type":24,"value":1328},"int",{"type":19,"tag":111,"props":1330,"children":1331},{"style":247},[1332],{"type":24,"value":1333}," initialTestValue",{"type":19,"tag":111,"props":1335,"children":1336},{"style":130},[1337],{"type":24,"value":269},{"type":19,"tag":111,"props":1339,"children":1340},{"class":113,"line":272},[1341,1346,1350],{"type":19,"tag":111,"props":1342,"children":1343},{"style":130},[1344],{"type":24,"value":1345},"    testValue ",{"type":19,"tag":111,"props":1347,"children":1348},{"style":169},[1349],{"type":24,"value":1293},{"type":19,"tag":111,"props":1351,"children":1352},{"style":130},[1353],{"type":24,"value":1354}," initialTestValue;\n",{"type":19,"tag":111,"props":1356,"children":1357},{"class":113,"line":306},[1358],{"type":19,"tag":111,"props":1359,"children":1360},{"style":130},[1361],{"type":24,"value":312},{"type":19,"tag":111,"props":1363,"children":1364},{"class":113,"line":315},[1365],{"type":19,"tag":111,"props":1366,"children":1367},{"emptyLinePlaceholder":140},[1368],{"type":24,"value":143},{"type":19,"tag":111,"props":1370,"children":1371},{"class":113,"line":368},[1372,1376,1380],{"type":19,"tag":111,"props":1373,"children":1374},{"style":169},[1375],{"type":24,"value":213},{"type":19,"tag":111,"props":1377,"children":1378},{"style":221},[1379],{"type":24,"value":787},{"type":19,"tag":111,"props":1381,"children":1382},{"style":130},[1383],{"type":24,"value":1384}," TestValue {\n",{"type":19,"tag":111,"props":1386,"children":1387},{"class":113,"line":397},[1388,1393,1398,1402],{"type":19,"tag":111,"props":1389,"children":1390},{"style":221},[1391],{"type":24,"value":1392},"    get",{"type":19,"tag":111,"props":1394,"children":1395},{"style":130},[1396],{"type":24,"value":1397}," { ",{"type":19,"tag":111,"props":1399,"children":1400},{"style":118},[1401],{"type":24,"value":849},{"type":19,"tag":111,"props":1403,"children":1404},{"style":130},[1405],{"type":24,"value":1406}," testValue; }\n",{"type":19,"tag":111,"props":1408,"children":1409},{"class":113,"line":405},[1410,1415,1420,1424],{"type":19,"tag":111,"props":1411,"children":1412},{"style":221},[1413],{"type":24,"value":1414},"    set",{"type":19,"tag":111,"props":1416,"children":1417},{"style":130},[1418],{"type":24,"value":1419}," { testValue ",{"type":19,"tag":111,"props":1421,"children":1422},{"style":169},[1423],{"type":24,"value":1293},{"type":19,"tag":111,"props":1425,"children":1426},{"style":130},[1427],{"type":24,"value":1428}," value; }\n",{"type":19,"tag":111,"props":1430,"children":1431},{"class":113,"line":458},[1432],{"type":19,"tag":111,"props":1433,"children":1434},{"style":130},[1435],{"type":24,"value":312},{"type":19,"tag":111,"props":1437,"children":1438},{"class":113,"line":487},[1439],{"type":19,"tag":111,"props":1440,"children":1441},{"emptyLinePlaceholder":140},[1442],{"type":24,"value":143},{"type":19,"tag":111,"props":1444,"children":1445},{"class":113,"line":495},[1446,1450,1454,1458,1462,1466,1470,1474],{"type":19,"tag":111,"props":1447,"children":1448},{"style":169},[1449],{"type":24,"value":213},{"type":19,"tag":111,"props":1451,"children":1452},{"style":169},[1453],{"type":24,"value":1053},{"type":19,"tag":111,"props":1455,"children":1456},{"style":221},[1457],{"type":24,"value":787},{"type":19,"tag":111,"props":1459,"children":1460},{"style":232},[1461],{"type":24,"value":1018},{"type":19,"tag":111,"props":1463,"children":1464},{"style":130},[1465],{"type":24,"value":796},{"type":19,"tag":111,"props":1467,"children":1468},{"style":221},[1469],{"type":24,"value":875},{"type":19,"tag":111,"props":1471,"children":1472},{"style":247},[1473],{"type":24,"value":1031},{"type":19,"tag":111,"props":1475,"children":1476},{"style":130},[1477],{"type":24,"value":269},{"type":19,"tag":111,"props":1479,"children":1480},{"class":113,"line":548},[1481,1485,1490,1494,1498],{"type":19,"tag":111,"props":1482,"children":1483},{"style":118},[1484],{"type":24,"value":829},{"type":19,"tag":111,"props":1486,"children":1487},{"style":130},[1488],{"type":24,"value":1489}," (obj ",{"type":19,"tag":111,"props":1491,"children":1492},{"style":118},[1493],{"type":24,"value":1139},{"type":19,"tag":111,"props":1495,"children":1496},{"style":196},[1497],{"type":24,"value":1259},{"type":19,"tag":111,"props":1499,"children":1500},{"style":130},[1501],{"type":24,"value":1502},")\n",{"type":19,"tag":111,"props":1504,"children":1505},{"class":113,"line":577},[1506,1511,1516,1520,1525,1530,1535,1541],{"type":19,"tag":111,"props":1507,"children":1508},{"style":118},[1509],{"type":24,"value":1510},"       return",{"type":19,"tag":111,"props":1512,"children":1513},{"style":130},[1514],{"type":24,"value":1515}," TestValue.",{"type":19,"tag":111,"props":1517,"children":1518},{"style":232},[1519],{"type":24,"value":976},{"type":19,"tag":111,"props":1521,"children":1522},{"style":130},[1523],{"type":24,"value":1524},"(((",{"type":19,"tag":111,"props":1526,"children":1527},{"style":196},[1528],{"type":24,"value":1529},"SampleClass",{"type":19,"tag":111,"props":1531,"children":1532},{"style":130},[1533],{"type":24,"value":1534},") obj).",{"type":19,"tag":111,"props":1536,"children":1538},{"style":1537},"--shiki-default:#35A77C;--shiki-dark:#F8F8F2",[1539],{"type":24,"value":1540},"TestValue",{"type":19,"tag":111,"props":1542,"children":1543},{"style":130},[1544],{"type":24,"value":1036},{"type":19,"tag":111,"props":1546,"children":1547},{"class":113,"line":585},[1548],{"type":19,"tag":111,"props":1549,"children":1550},{"style":118},[1551],{"type":24,"value":1552},"    else\n",{"type":19,"tag":111,"props":1554,"children":1555},{"class":113,"line":638},[1556,1560,1564,1568],{"type":19,"tag":111,"props":1557,"children":1558},{"style":118},[1559],{"type":24,"value":1510},{"type":19,"tag":111,"props":1561,"children":1562},{"style":169},[1563],{"type":24,"value":903},{"type":19,"tag":111,"props":1565,"children":1566},{"style":296},[1567],{"type":24,"value":908},{"type":19,"tag":111,"props":1569,"children":1570},{"style":130},[1571],{"type":24,"value":133},{"type":19,"tag":111,"props":1573,"children":1574},{"class":113,"line":667},[1575],{"type":19,"tag":111,"props":1576,"children":1577},{"style":130},[1578],{"type":24,"value":312},{"type":19,"tag":111,"props":1580,"children":1581},{"class":113,"line":675},[1582],{"type":19,"tag":111,"props":1583,"children":1584},{"emptyLinePlaceholder":140},[1585],{"type":24,"value":143},{"type":19,"tag":111,"props":1587,"children":1588},{"class":113,"line":728},[1589,1593,1597,1601,1605],{"type":19,"tag":111,"props":1590,"children":1591},{"style":169},[1592],{"type":24,"value":213},{"type":19,"tag":111,"props":1594,"children":1595},{"style":169},[1596],{"type":24,"value":1053},{"type":19,"tag":111,"props":1598,"children":1599},{"style":221},[1600],{"type":24,"value":787},{"type":19,"tag":111,"props":1602,"children":1603},{"style":232},[1604],{"type":24,"value":1062},{"type":19,"tag":111,"props":1606,"children":1607},{"style":130},[1608],{"type":24,"value":1609},"() {\n",{"type":19,"tag":111,"props":1611,"children":1612},{"class":113,"line":757},[1613,1617,1621,1626],{"type":19,"tag":111,"props":1614,"children":1615},{"style":118},[1616],{"type":24,"value":278},{"type":19,"tag":111,"props":1618,"children":1619},{"style":130},[1620],{"type":24,"value":1515},{"type":19,"tag":111,"props":1622,"children":1623},{"style":232},[1624],{"type":24,"value":1625},"GetHashCode",{"type":19,"tag":111,"props":1627,"children":1628},{"style":130},[1629],{"type":24,"value":1067},{"type":19,"tag":111,"props":1631,"children":1632},{"class":113,"line":765},[1633],{"type":19,"tag":111,"props":1634,"children":1635},{"style":130},[1636],{"type":24,"value":312},{"type":19,"tag":111,"props":1638,"children":1639},{"class":113,"line":773},[1640],{"type":19,"tag":111,"props":1641,"children":1642},{"style":130},[1643],{"type":24,"value":1209},{"type":19,"tag":20,"props":1645,"children":1646},{},[1647],{"type":24,"value":1648},"As with all code, determine the suitability of this solution to your own needs, and that responsibility is yours. As with all code here it comes without warranty, expressed, implied or otherwise alluded to.",{"type":19,"tag":20,"props":1650,"children":1651},{},[1652,1654,1661],{"type":24,"value":1653},"I’d recommend checking out the performance, ",{"type":19,"tag":42,"props":1655,"children":1658},{"href":1656,"rel":1657},"https://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconoperatoroverloadingusageguidelines.asp",[46],[1659],{"type":24,"value":1660},"CLS compliance regarding operators",{"type":24,"value":1662}," and the addition of any extra operators you use all the time.",{"type":19,"tag":20,"props":1664,"children":1665},{},[1666],{"type":19,"tag":1667,"props":1668,"children":1669},"em",{},[1670],{"type":24,"value":1671},"[)amien",{"type":19,"tag":1673,"props":1674,"children":1675},"style",{},[1676],{"type":24,"value":1677},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":105,"searchDepth":136,"depth":136,"links":1679},[],"markdown","content:blog:2005:automaticcomparisonoperatoroverloadingincsharp.md","content","blog/2005/automaticcomparisonoperatoroverloadingincsharp.md","blog/2005/automaticcomparisonoperatoroverloadingincsharp","md","/blog/2005/automaticcomparisonoperatoroverloadingincsharp/",533,[1689,1693,1697],{"title":1690,"date":1691,"url":1692},"HTML5 Video Cheatsheet: Optimizing videos for the web","2025-12-05T00:00:00Z","/blog/2025/html5-video-cheatsheet/",{"title":1694,"date":1695,"url":1696},"Transactions in the MongoDB EF Core Provider","2025-10-25","/blog/2025/mongodb-explicit-transactions/",{"title":1698,"date":1699,"url":1700},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","/blog/2025/mongodb-queryable-encryption/",[1702],{"_path":1703,"_dir":1704,"_draft":6,"_partial":6,"_locale":7,"title":1705,"description":1706,"id":1707,"name":1708,"email":1709,"avatar":1710,"date":1711,"body":1712,"_type":1680,"_id":2017,"_source":1682,"_file":2018,"_stem":2019,"_extension":1685},"/comments/automaticcomparisonoperatoroverloadingincsharp/42124","automaticcomparisonoperatoroverloadingincsharp","42124","Very nice. Saves me quite a bit of typing.",42124,"bob r","xvn320b@yahoo.com","https://www.gravatar.com/avatar/bdec9021a75c519f92b43b75f3206c8b?r=pg&d=retro","2010-07-19T16:01:10",{"type":16,"children":1713,"toc":2015},[1714,1718,1723,1842,1847,1852,1996,2001,2006,2011],{"type":19,"tag":20,"props":1715,"children":1716},{},[1717],{"type":24,"value":1706},{"type":19,"tag":20,"props":1719,"children":1720},{},[1721],{"type":24,"value":1722},"A (very) minor issue:",{"type":19,"tag":100,"props":1724,"children":1726},{"className":102,"code":1725,"language":104,"meta":105,"style":105},"public override bool Equals(object obj) {\n    if (!(obj is AutoOperators)) return false;\n    return this == (AutoOperators) obj;\n}\n",[1727],{"type":19,"tag":70,"props":1728,"children":1729},{"__ignoreMap":105},[1730,1765,1808,1835],{"type":19,"tag":111,"props":1731,"children":1732},{"class":113,"line":114},[1733,1737,1741,1745,1749,1753,1757,1761],{"type":19,"tag":111,"props":1734,"children":1735},{"style":169},[1736],{"type":24,"value":172},{"type":19,"tag":111,"props":1738,"children":1739},{"style":169},[1740],{"type":24,"value":1053},{"type":19,"tag":111,"props":1742,"children":1743},{"style":221},[1744],{"type":24,"value":224},{"type":19,"tag":111,"props":1746,"children":1747},{"style":232},[1748],{"type":24,"value":1096},{"type":19,"tag":111,"props":1750,"children":1751},{"style":130},[1752],{"type":24,"value":796},{"type":19,"tag":111,"props":1754,"children":1755},{"style":221},[1756],{"type":24,"value":875},{"type":19,"tag":111,"props":1758,"children":1759},{"style":247},[1760],{"type":24,"value":1031},{"type":19,"tag":111,"props":1762,"children":1763},{"style":130},[1764],{"type":24,"value":269},{"type":19,"tag":111,"props":1766,"children":1767},{"class":113,"line":136},[1768,1772,1776,1780,1784,1788,1792,1796,1800,1804],{"type":19,"tag":111,"props":1769,"children":1770},{"style":118},[1771],{"type":24,"value":829},{"type":19,"tag":111,"props":1773,"children":1774},{"style":130},[1775],{"type":24,"value":240},{"type":19,"tag":111,"props":1777,"children":1778},{"style":169},[1779],{"type":24,"value":1129},{"type":19,"tag":111,"props":1781,"children":1782},{"style":130},[1783],{"type":24,"value":1134},{"type":19,"tag":111,"props":1785,"children":1786},{"style":118},[1787],{"type":24,"value":1139},{"type":19,"tag":111,"props":1789,"children":1790},{"style":196},[1791],{"type":24,"value":188},{"type":19,"tag":111,"props":1793,"children":1794},{"style":130},[1795],{"type":24,"value":1148},{"type":19,"tag":111,"props":1797,"children":1798},{"style":118},[1799],{"type":24,"value":849},{"type":19,"tag":111,"props":1801,"children":1802},{"style":296},[1803],{"type":24,"value":1157},{"type":19,"tag":111,"props":1805,"children":1806},{"style":130},[1807],{"type":24,"value":133},{"type":19,"tag":111,"props":1809,"children":1810},{"class":113,"line":146},[1811,1815,1819,1823,1827,1831],{"type":19,"tag":111,"props":1812,"children":1813},{"style":118},[1814],{"type":24,"value":278},{"type":19,"tag":111,"props":1816,"children":1817},{"style":1172},[1818],{"type":24,"value":1175},{"type":19,"tag":111,"props":1820,"children":1821},{"style":169},[1822],{"type":24,"value":427},{"type":19,"tag":111,"props":1824,"children":1825},{"style":130},[1826],{"type":24,"value":240},{"type":19,"tag":111,"props":1828,"children":1829},{"style":196},[1830],{"type":24,"value":75},{"type":19,"tag":111,"props":1832,"children":1833},{"style":130},[1834],{"type":24,"value":1192},{"type":19,"tag":111,"props":1836,"children":1837},{"class":113,"line":156},[1838],{"type":19,"tag":111,"props":1839,"children":1840},{"style":130},[1841],{"type":24,"value":1209},{"type":19,"tag":20,"props":1843,"children":1844},{},[1845],{"type":24,"value":1846},"Will cause \"Code Analysis\" (FxCop ??) to issue a\n\"Warning 1 CA1800 : Microsoft.Performance : 'obj', a parameter, is cast to type 'AutoOperators' multiple times in method 'AutoOperators.Equals(object)'. Cache the result of the 'as' operator or direct cast in order to eliminate the redundant castclass instruction. ..\\AutoOperators.cs 54\"",{"type":19,"tag":20,"props":1848,"children":1849},{},[1850],{"type":24,"value":1851},"Changing it to:",{"type":19,"tag":100,"props":1853,"children":1855},{"className":102,"code":1854,"language":104,"meta":105,"style":105},"public override bool Equals(object obj) {\n    AutoOperators other = obj as AutoOperators;\n    return (other != null) ? (this == other) : false;\n}\n",[1856],{"type":19,"tag":70,"props":1857,"children":1858},{"__ignoreMap":105},[1859,1894,1929,1989],{"type":19,"tag":111,"props":1860,"children":1861},{"class":113,"line":114},[1862,1866,1870,1874,1878,1882,1886,1890],{"type":19,"tag":111,"props":1863,"children":1864},{"style":169},[1865],{"type":24,"value":172},{"type":19,"tag":111,"props":1867,"children":1868},{"style":169},[1869],{"type":24,"value":1053},{"type":19,"tag":111,"props":1871,"children":1872},{"style":221},[1873],{"type":24,"value":224},{"type":19,"tag":111,"props":1875,"children":1876},{"style":232},[1877],{"type":24,"value":1096},{"type":19,"tag":111,"props":1879,"children":1880},{"style":130},[1881],{"type":24,"value":796},{"type":19,"tag":111,"props":1883,"children":1884},{"style":221},[1885],{"type":24,"value":875},{"type":19,"tag":111,"props":1887,"children":1888},{"style":247},[1889],{"type":24,"value":1031},{"type":19,"tag":111,"props":1891,"children":1892},{"style":130},[1893],{"type":24,"value":269},{"type":19,"tag":111,"props":1895,"children":1896},{"class":113,"line":136},[1897,1902,1907,1911,1916,1921,1925],{"type":19,"tag":111,"props":1898,"children":1899},{"style":196},[1900],{"type":24,"value":1901},"    AutoOperators",{"type":19,"tag":111,"props":1903,"children":1904},{"style":130},[1905],{"type":24,"value":1906}," other ",{"type":19,"tag":111,"props":1908,"children":1909},{"style":169},[1910],{"type":24,"value":1293},{"type":19,"tag":111,"props":1912,"children":1913},{"style":130},[1914],{"type":24,"value":1915}," obj ",{"type":19,"tag":111,"props":1917,"children":1918},{"style":118},[1919],{"type":24,"value":1920},"as",{"type":19,"tag":111,"props":1922,"children":1923},{"style":196},[1924],{"type":24,"value":188},{"type":19,"tag":111,"props":1926,"children":1927},{"style":130},[1928],{"type":24,"value":133},{"type":19,"tag":111,"props":1930,"children":1931},{"class":113,"line":146},[1932,1936,1941,1945,1949,1953,1958,1962,1967,1971,1976,1981,1985],{"type":19,"tag":111,"props":1933,"children":1934},{"style":118},[1935],{"type":24,"value":278},{"type":19,"tag":111,"props":1937,"children":1938},{"style":130},[1939],{"type":24,"value":1940}," (other ",{"type":19,"tag":111,"props":1942,"children":1943},{"style":169},[1944],{"type":24,"value":566},{"type":19,"tag":111,"props":1946,"children":1947},{"style":296},[1948],{"type":24,"value":889},{"type":19,"tag":111,"props":1950,"children":1951},{"style":130},[1952],{"type":24,"value":894},{"type":19,"tag":111,"props":1954,"children":1955},{"style":169},[1956],{"type":24,"value":1957},"?",{"type":19,"tag":111,"props":1959,"children":1960},{"style":130},[1961],{"type":24,"value":240},{"type":19,"tag":111,"props":1963,"children":1964},{"style":1172},[1965],{"type":24,"value":1966},"this",{"type":19,"tag":111,"props":1968,"children":1969},{"style":169},[1970],{"type":24,"value":427},{"type":19,"tag":111,"props":1972,"children":1973},{"style":130},[1974],{"type":24,"value":1975}," other) ",{"type":19,"tag":111,"props":1977,"children":1978},{"style":169},[1979],{"type":24,"value":1980},":",{"type":19,"tag":111,"props":1982,"children":1983},{"style":296},[1984],{"type":24,"value":1157},{"type":19,"tag":111,"props":1986,"children":1987},{"style":130},[1988],{"type":24,"value":133},{"type":19,"tag":111,"props":1990,"children":1991},{"class":113,"line":156},[1992],{"type":19,"tag":111,"props":1993,"children":1994},{"style":130},[1995],{"type":24,"value":1209},{"type":19,"tag":20,"props":1997,"children":1998},{},[1999],{"type":24,"value":2000},"makes the \"Code Analysis\" program happy. The same issue arises in the \"CompareTo\" override.",{"type":19,"tag":20,"props":2002,"children":2003},{},[2004],{"type":24,"value":2005},"The if/else structure does work better if the comparison requires more than a simple expression while the conditional operator is very concise if a simple expression will do the job.",{"type":19,"tag":20,"props":2007,"children":2008},{},[2009],{"type":24,"value":2010},"Thanks,\nBob R",{"type":19,"tag":1673,"props":2012,"children":2013},{},[2014],{"type":24,"value":1677},{"title":105,"searchDepth":136,"depth":136,"links":2016},[],"content:comments:automaticcomparisonoperatoroverloadingincsharp:42124.md","comments/automaticcomparisonoperatoroverloadingincsharp/42124.md","comments/automaticcomparisonoperatoroverloadingincsharp/42124",1779264598098]