c# - Why is my code leaving an item off of the list on every case? -


I am working on this training video. I saw in my example below that my code leaves the last item of the list every time. Before I made the code more fancy and readable

Question: Why is my code leaving the last item?

  Software & lt; String, sorted & lt; Employee & gt; & Gt;   

code:

  using the system; Using System.Collections.Generic; Using System.Linq; Using System.Text; Namespace Console Application 1 {Class Program {Private Zero Print-Oxide (dictionary & lt; string; list & gt; employee & gt; & gt; InputDictionaryParm1) {foreach (Inverted in InputDictionaryParm1) {Console.WriteLine (a.Key) ); Foreign (preference in a.value) {Console.WriteLine ("\ t" + E. Names); }} Console. Readkey (); } Static zero main (string [] args) {var d = new department collection (); D.AddDept ("AA", new employee {name = "L"}). Rude ("AA", new employee {name = "A"}); ("BB", new employee {name = "e"}). Vulgar ("BB", new employee {name = "F"), adidepet ("BB", new employee {name = "D"})}). Vulgar ("BB", new employee {name = "A"}); ("Cc", new employee {name = "z"}). Rude ("cc", new employee {name = "x"), adidepet ("cc", new employee {name = "j"}}}). Rude ("cc", new employee {name = "y"}); ("DD", new employee {name = "W"}). Rude ("DD", new employee {name = "e"), adidepet ("DD", new employee {name = "t"}}}). Rude ("DD", new employee {name = "A"}); Foreign (AAd) {Console.WriteLine (a.Key); Foreign (preference in a.value) {Console.WriteLine ("\ t" + e.Name); }} Console. Readkey (); // printDictionary (d); }} Public Class Employee Commander: IQ Quality Comparator & lt; Employee & gt ;, IComparer & lt; Employee & gt; {Public Employee Commander () {} Public Child Equal (Employee X, Employee Y) {Return String.Aquals (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); }} Public Section Department Collection: Sorted Objects & lt; String, sorted & lt; Employee & gt; & Gt; {Public Department Collections (Console). Light Line ("Department Collection"); } Public Department Collection Adddept (String D, Employee E) {if (includes (D)) {this [D]. Add (e); } Other {ADD (D, NEW SOURCED SEAT & lt; Employee & gt; (New Staff Companion ()); } Return it; }}}   

Screen shot:

Enter the image Here's the description

Your adddept method does not actually add value If the key is unavailable:

  public department archive AddDept (string D, employee E) {if (included in (D)) {this [D]. Add (e); } Other {ADD (D, NEW SORTEDSSE & lt; Employee & gt; (New Staff Companion ()); // Add it! This [d] .add (e); } Return it; }   

Note that you can reverse the conditional to simplify this code:

  Public Department Adddept (String D, Employee E) { If (! D)) {ADD (D, NEW SORTEDSSE & lt; Employee & gt; (New Staff Companion ()); } This [D] Add (e); Back it; }    

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 -