public struct PLU
{
public int ID { get; set; }
public string name { get; set; }
public double price { get; set; }
public int quantity {get;set;}
}
public static ObservableCollection<PLU> PLUList = new ObservableCollection<PLU>();
我有上述的ObservableCollection
。现在我想要搜索PLUList
中的ID
,并像这样获取其索引:
int index = PLUList.indexOf();
if (index > -1)
{
// Do something here
}
else
{
// Do sth else here..
}
有什么快速的解决方法?
编辑:
假设已经向PLUList
添加了一些项目,并且我想添加另一个新项目。 但在添加之前,我想检查列表中是否已存在ID
。 如果存在,则希望将quantity
加1。