-1

Tried searching online. But couldn't find an answer:

public class A
{
    public Dictionary<int, string> Dict { get; } = new Dictionary<int, string>();
}

var list = new List<A>();
var a = new A();
a.Dict.Add(1, "A");

var b = new A();
b.Dict.Add(2, "A");

list.Add(a);
list.Add(b);

How to get the maximum and minimum key in dictionary.

max key is 2 and min key is 1.

var max = list.Max(e => e.Dict.??); // 
Gauravsa
  • 6,330
  • 2
  • 21
  • 30

1 Answers1

0

You can use Dictionary.Keys property for this:

var max = list.Max(e => e.Dict.Keys.Max())

or

var max = list.SelectMany(e => e.Dict.Keys).Max()
Guru Stron
  • 102,774
  • 10
  • 95
  • 132