Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.80 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. SortedHashTable in c#
  2. var toDelete = new HashSet<T>();
  3. foreach (var item in sortedItems)
  4. {
  5.     if (!toDelete.Contains(item))
  6.     {
  7.         toDelete.Add(item);
  8.         // do something with item here
  9.     }
  10.     foreach (var dependentFirst in item.DependentElements)
  11.     {
  12.         if (!toDelete.Contains(item))
  13.         {
  14.             toDelete.Add(dependentFirst);
  15.             // do something with item here
  16.         }
  17.     }
  18. }
  19. sortedItems.RemoveAll(i => toDelete.Contains(i));
  20.        
  21. var dictionary = new Dictionary<string, int>();
  22.             dictionary.Add("car", 2);
  23.             dictionary.Add("apple", 1);
  24.             dictionary.Add("zebra", 0);
  25.             dictionary.Add("mouse", 5);
  26.             dictionary.Add("year", 3);
  27.             dictionary = dictionary.OrderBy(o => o.Key).ToDictionary(o => o.Key, o => o.Value);