0
我有以下結構:獲得最長的名單數的清單內使用LINQ
class Attribute
{
List<Value> values;
}
List<Attribute> attributes;
我需要從屬性的列表中獲得最長List<Value>
的計數。 有沒有使用Linq的簡單解決方案?
我已經試過兩個嵌套循環,這不是很高效。
我有以下結構:獲得最長的名單數的清單內使用LINQ
class Attribute
{
List<Value> values;
}
List<Attribute> attributes;
我需要從屬性的列表中獲得最長List<Value>
的計數。 有沒有使用Linq的簡單解決方案?
我已經試過兩個嵌套循環,這不是很高效。
var max = attributes.Max(a => a.values.Count)
您可以使用Enumerable.Max使用Count
屬性獲取最大大小的列表。
var max = attributes.Max(lst=>lst.values.Count);
尼斯和簡單,謝謝 – Matthias