var Table = new List();
var partlist = Table
.AsEnumerable()
.Where(row =>
{
if (!string.IsNullOrEmpty(row.Field<string>("Column1")) &&
row.Field<string>("Column1").Equals(variableName1) &&
!string.IsNullOrEmpty(row.Field<string>("Column2")) &&
row.Field<string>("Column2").Equals(variableName2))
return true;
return false;
})
.Select(row =>
{
return new
{
PartNumber = row.Field<string>("HardwareType"),
Number = row.Field<string>("HardwareSerialNo")
};
})
.Distinct();
var distinctParts =
partlist
.Select(part => { return part.PartNumber; })
.Distinct();
foreach (var distinctPart in distinctParts)
{
var list = partlist.Where(part =>
{
if (part.PartNumber.Equals(distinctPart))
return true;
return false;
})
.Select(part => { return part.Number; })
.Distinct();
int quantity = list.Count();
hwList[distinctPart] = quantity;
}
上面的代码运行良好,但执行时间很长。有什么方法可以最小化代码并提高性能。请帮帮我