2011-09-26 35 views
0

我有這樣的列表:檢查所有腦幹

List<int> baslikIndexes = new List<int> { }; 

和我手動添加的元素。我想知道例如元素「23」是否在其中。我試圖使用「存在」方法,但我還沒有想出如何使用它。我想這和它給錯誤:

baslikIndexes.Exists(Predicate<int>(23)); // I try to check whether 23 is in the list or not 

感謝您的幫助..

+0

只是使用包含? –

+0

http://msdn.microsoft.com/en-us/library/bhkz42b3.aspx –

回答

1
List<int> lstint = new List<int>() { 5, 15, 23, 256, 55 }; 
bool ysno = lstint.Exists(p => p == 23); 
6

使用baslikIndexes.Contains(23);

1

您應該使用baslikIndexes.Contains(23)在這裏,但如果你想使用Exists()方法你可以這樣使用它:

baslikIndexes.Exists(x => x == 23); 

瞭解更多關於Lambda Expressions在MSDN上。