我有以下的类:
但是它太丑陋和冗长,每次写它都想吐。 有什么好的建议吗?
public class Element
{
public List<int> Ints
{
get;private set;
}
}
如果给定一个List<Element>
,如何使用LINQ查找List<Element>
中所有Ints
的列表?
我可以使用以下代码:
public static List<int> FindInts(List<Element> elements)
{
var ints = new List<int>();
foreach(var element in elements)
{
ints.AddRange(element.Ints);
}
return ints;
}
}
但是它太丑陋和冗长,每次写它都想吐。 有什么好的建议吗?