From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

The Contains method

The Contains method

- [Instructor] Next on the list is the Contains extension method. It's used to return whether a specified item is contained in the sequence. Now that sounds familiar. In the last video you looked at any and it says it determines whether an element of a sequence exists or satisfies a condition. So what's the difference between the two? Any takes a predicate as a parameter, contains on the other hand, takes an object as a parameter. So for example, on these first two lines of code, on line three and four, I'm creating a list of integers so when I call contains, I pass in an integer for the test. And I get back. True, the list of integers contains 14. What about when I work with one of my web color types like I'm doing here? I have a list of web colors. So now when I want to do my test here I have to pass in a reference to a web color for the test. So in order to do that, I've got two examples. I…

Contents