Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,
Is there a method to check if an item belongs to a list of the same type without using for loop, thanks in advance
Posted

1 solution

Hi,

Use the List(T).Contains method[^]
For example:
C#
bool b = integerList.Contains(2);

Or, use the Enumerable.Any method[^] if you want to use a lambda expression.
For example, if you have a list of cars.
C#
bool b = carList.Any(a => a.Id == 1001);

Hope this helps.
 
Share this answer
 
v2
Comments
z3ngew 26-Jan-13 9:39am    
Works Great, Thank you very much
Thomas Daniels 26-Jan-13 9:42am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900