考虑以下代码片段:
// get number of sheep in DataTable by counting UID's
Double n = DataTableContainingSheep.AsEnumerable().Sum(r => (Int32)r["sheepId"])
我想要只计算DataTable中的黑羊?有什么方法可以将select子句放入Sum()
函数吗?
答案 0 :(得分:2)
应该是这样的:
Double n =
DataTableContainingSheep
.AsEnumerable()
.Where(r => (String)r["color"] == "black")
.Sum(r => (Double)r["sheepId"]);