How to check whether a List contains a specified element in C#? While looking for a solution to this inquiry, I’ve run into comparative ones using LINQ yet I haven’t had the option to completely get them (and accordingly, execute them), as I’m not acclimated with it. What I might want to, fundamentally, is this:
List is an assortment of things/components. You can check assuming the rundown contains a thing or an article is available in the rundown. In this instructional exercise, we will figure out how to check if a thing/component is available in a given List.
List<T>.Contains(T) Method is utilized to check whether or not a component is in the List<T>.
Properties of List:
- It is unique in relation to the exhibits. A rundown can be resized progressively however clusters can’t.
- List class can acknowledge invalid as a legitimate incentive for reference types and it likewise permits copy components.
- In the event that the Count becomes equivalents to Capacity, the limit of the List increments consequently by redistributing the inward cluster. The current components will be duplicated to the new cluster before the expansion of the new component.
public bool Contains (T item);
Here, thing is the item which is to be situate in the List<T>. The worth can be invalid for reference types.
Bring Value back: This strategy returns True in the event that the thing is found in the List<T> in any case gets back False.
Underneath programs represent the utilization of List<T>.Contains(T) Method: