checking existance of the list element via c# functions
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.
精彩评论