开发者

checking existance of the list element via c# functions

开发者 https://www.devze.com 2023-04-07 19:38 出处:网络
I have a list like: List<int> baslikIndexes = new List<int> { }; and I added the elements manually. I want to know whether for example if element \"23\" is in it or not. I am trying to

I have a list like:

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

and I added the elements manually. I want to know whether for example if element "23" is in it or not. I am trying to use "Exists" method but I haven't figured out how to use it. I tried t开发者_Go百科his and it gives error:

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

Thanks for help..


use baslikIndexes.Contains(23);


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


You should be using baslikIndexes.Contains(23) here, but if you'd like to use the Exists() method you can use it like this:

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

Read more about Lambda Expressions on MSDN.

0

精彩评论

暂无评论...
验证码 换一张
取 消