Feedback

Kleinsten key in einem Dictionary mit LINQ abfragen

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);

1 Kommentar