声明ObservableCollection类型,方便记录集合变更
private ObservableCollection<TManufOrdEx> _ManufOrdExList;
/// <summary>生产订单列表</summary>
public ObservableCollection<TManufOrdEx> ManufOrdExList { get { return _ManufOrdExList; } set { _ManufOrdExList = value; RaisePropertyChanged(); } }
根据某个字段分组、求和
List<TManufOrdEx> manufDisLineNos = manufOrdList.Where((x, i) => manufOrdList.FindIndex(z => z.sellConLineNo == x.sellConLineNo) == i).ToList();
sumKgs = manufDisLineNos.Sum(t => t.kgs);
往新的集合中添加数据,已经加过的不加(去重)
List<TManufOrdEx> copyList = new List<TManufOrdEx>();
foreach (TManufOrdEx str in ManufOrdList)//源LIST去重
{
if (copyList.Count > 0)
{
bool IsRepeat = copyList.Any<TManufOrdEx>(p => p.id == str.id);
if (IsRepeat)
{
continue;
}
else
{
copyList.Add(str);
}
}
else
{
copyList.Add(str);
}
}
ManufOrdList = new List<TManufOrdEx>();
ManufOrdList = copyList;
List合并
List<int> listA = new List<int> {1,2,3,5,7,9};
List<int> listB = new List<int> {13,4,17,29,2};
List<int> Result = listA.Union(listB).ToList<int>(); //剔除重复项
List<int> Result = listA.Concat(listB).ToList<int>();//保留重复项
int count=listA.BinarySearch("1"); //判断集合中是否包含某个值.如果包含则返回0
排序
lisrt.Sort((l, r) => l.TransPlanType.CompareTo(r.TransPlanType));