c# - How is the Equals, GetHashCode, and Compare called from the following code? (Mystery) -


This code works but none of the methods listed how it does the actual call. It works but it seems to be about how magic is and why it works. I am never equal, or GetHashCode, or not the comparison but the code works. I do not call anything in the Constructor for the Employee Comparative Class. Which applies two interfaces.

Question: Is this done automatically only when new keys are installed in the class? (Some items are not just fine)

  Public Class Employee Commander: IEqualityComparer & lt; Employee & gt ;, IComparer & lt; Employee & gt; Employee Compan:  
  public child equivalent (employee X, employee Y) {return string.qualz (x.Name, y.Name); } Public athoshcode (employee obje) {back obj no Gatehashcode (); } Compare to public intervals (employee X, employee Y) {return string. Compiler (x.Name, y.Name); }   

class:

  using the system; Using System.Collections.Generic; Using System.Linq; Using System.Text; Namespace Console Application 1 {Class Program {Public Representative Zero (String E); Dell Handler = DelegateMappe; Dictionary & lt; String, list & lt; Employee & gt; & Gt; D = new dictionary & lt; String, list & lt; Employee & gt; & Gt; (); Public Static Zero DelegateMethod (String Message) {System.Console.WriteLine (Message); System.Console.ReadKey (); } Public Zero Test DL (Dale D) {D. Invoke ("el"); } Static zero main (string [] args) {program p = new program (); //p.handler ("Hello world"); //p.handler("DisneyLand "); //p.handler("Cattle Wars "); //p.testDel(p.handler); Var d = new ordering layer & lt; String, sorted & lt; Employee & gt; & Gt; (); // hashett no duplicates d.Add ("AA", new sorted employee & employee; (new employee compaion ()); D ["AA"]. Add (new employee {name = "A"}); D ["AA"]. Add (new employee {name = "b"}); D ["AA"]. Add (new employee {name = "c"}); D ["AA"]. Add (new employee {name = "c"}); D ["AA"]. Add (new employee {name = "c"}); d.Add ("BB", New Surrended & lt; Employee & gt; (New Staff Companion ()); D ["B"]. Add (new employee {name = "e"}); D ["BB"] Add (new employee {name = "f"}); D ["BB"] Add (new employee {name = "A"}); D. Add ("cc", new sorted & lt; employee & gt; (new employee comparter ()); D ["CC"]. Add (new employee {name = "z"}); D ["CC"]. Add (new employee {name = "x"}); D ["CC"]. Add (new employee {name = "y"}); D. Add ("DD", the new sorted employee & gt; employee & gt; (new employee compiler); d ["dd"]. Add (new employee {name = "jade"}); d ["dd"]. Add (new employee {name = "u"}); d ["dd"]. Add (new employee {name = "u"}); d ["dd"]. Add (new employee {name = "q" }; [["DD"]. Add (new employee {name = "y"}); foreign (an ad) {Console.WriteLine (a.Key); foreign (preference in a.value) {Console. WriteLine ("\ t" + e.Name);}} console.readkey ();}} public class Chair Commander: IEquality Comparator & lt; Employee & gt ;, IComparer & lt; Employee & gt; {Public Staff Commander () {} Public Child Equal (Employee X, Employee Y) {Return String.Equalz (X. Name, y .Name);} Public at Hoshcod (Employee OBJ) {Back Obj. No. Gatehashcod ();} Compare to Public Interference (Employee X, Employee Y) {return string compiler (x.Name, y.Name);} }}    

This bulk Le is not magic. The implementation calls compare (in your example, some call GetHashCode or Equals ) is not. It looks like you do the following:

  Zero main () {MyMethod (New Employee Compaired ()); } Zero MyMethod (IComparer & lt; employee & gt; Comparator) {var emp1 = new employee {name = "George"}; Var emp2 = new employee {name = "tom"}; Console.light line (comparison compile (amp1, amp2)); } In the perspective of  main  from   

, do not ever compare it , it's only a new The method that is called it is the one that has compare .

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -