尝试在网上搜索。 却找不到答案:
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);
如何获取字典中的最大和最小键。
最大键为2,最小键为1。
var max = list.Max(e => e.Dict.??); //
可以为此使用Dictionary.Keys
属性:
var max = list.Max(e => e.Dict.Keys.Max())
或
var max = list.SelectMany(e => e.Dict.Keys).Max()