這是類定義
public class collection
{
public string exceptionId;
public string exceptionname;
}
//這里判斷是否存在的代碼,該代碼能正常用。但是不需要用lamda運算式如果用Exits來查看元素是否存在呢?
if (list.Exists(tmp => tmp.exceptionId == id) == false)
{
// //增加進來
collection collection = new collection();
collection.exceptionId = id;
collection.exceptionname = idname;
// list.Add(collection);
}
引數需要Predicate<collection> predicate的委托
后面不知道怎么寫了。
意思是list中的某一個collection .Id與傳入的引數Id一致則不向list中增加。
謝謝!
uj5u.com熱心網友回復:
自己多載compare方法,對比物件屬性uj5u.com熱心網友回復:
if(list.where(x=>x.Id==id).toList().Count>0)uj5u.com熱心網友回復:
不使用lamda運算式,是怎么做呢uj5u.com熱心網友回復:
2樓的辦法就行uj5u.com熱心網友回復:
ConcurrentDictionary<T1, T2>AddOrUpdate
uj5u.com熱心網友回復:
var exist=list.Any(item=>item.exceptionId==id);if(exist)
{
//todo:如果存在的邏輯
}else
{
//todo:如果不存在的邏輯
}
uj5u.com熱心網友回復:
汗,不用lambda啊.....轉載請註明出處,本文鏈接:https://www.uj5u.com/net/253281.html
標籤:C#
