List<long> a;a里面包含的元素1,2,3,4,5現在要查詢的元素為 3我用 List<T>.Exists(3) 老用不起來望大家能指教一二 謝謝了
2 回答

忽然笑
TA貢獻1806條經驗 獲得超5個贊
exists的參數是predicate<T>,不是一個long型參數。
.net2.0 匿名委托方式: a.exists(delegate(long n) {return n == 3;})
.net3.5 lambda表達式: a.exists(n => n == 3)

慕田峪4524236
TA貢獻1875條經驗 獲得超5個贊
System.Collections.Generic.List<T>
public bool Exists(
Predicate<T> match
)
這個地方不應該用List<T>.Exists(3)這種吧……
這里應該用一個謂詞,也就是(xx 是 3)這種東西。一般用lambda表達式。
但是實際上一般查詢一個集合里面有沒有一個東西常用的是Dictionary<TKey, TValue>的ContainsKey方法或者HashSet<T>的Contains方法。
- 2 回答
- 0 關注
- 683 瀏覽
添加回答
舉報
0/150
提交
取消