Sprache: C#
Um aus einem Dictionary den kleinsten key abzufragen gibt es dank LINQ nun eine komfortable möglichkeit.
// Initialize Dictionary with sample values
Dictionary<int, double> listObject = new Dictionary<int,double>
{
{2004, 1.5}, {2005, 2.7}, {2006, 3.8}
};
// To get the min key use the Min-funktion
int minYear = listObject.Min(l => l.Key);
// Initialize Dictionary with sample values
Dictionary<int, double> listObject = new Dictionary<int,double>
{
{2004, 1.5}, {2005, 2.7}, {2006, 3.8}
};
// To get the min key use the Min-funktion
int minYear = listObject.Min(l => l.Key);
Alte URL:
/snippet/kleinsten-key-in-einem-dictionary-mit-linq-abfragen/747
Ich würde bevorzugen:
[code]var minYear = listObject.Keys.Min();[/code]