Posted by AlexanderZeitler on 2/27/2010 11:58 PM | Comments (0)

Angenommen, man möchte in einem Dictionary<double, string> den Eintrag finden, dessen Key (nicht Value, hierfür gibts Dictionary<TKey, TValue>.Min()) den kleinsten Wert hat, kann man das wie folgt lösen:

Dictionary<double, string> xValues = new Dictionary<double, string>();
xValues.Add(1, “Wert1”);
xValues.Add(2, “Wert2”);
double minX = xValues[xValues.Keys.Min()];

Die Keys-Property liefert eine Collection, die alle Keys des Dictionaries enthält.

Die Min()-Methode der Collection liefert dann den kleinsten Key-Wert, der als Index für das Dictionary dient und den Value zurückliefert.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Comments are closed