From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

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

Learn how to use the Any method to detect empty sequence

Learn how to use the Any method to detect empty sequence - .NET Tutorial

From the course: .NET Essentials: Working with LINQ

Learn how to use the Any method to detect empty sequence

- [Instructor] In this chapter, we're looking at the quantify operators and they're used to determine if there're interesting items that we want in a list. I'll start by looking at the Any extension method. There are two overloads of this method that serve different purposes. In this video, I'll look at the overload that takes no parameters, and this is used to determine, if there's one, or more items in the list. Another way of saying that, is we can use it to determine whether a list is empty. Now there's another method that you can use called Count, that is also used for this purpose. So I thought I would talk about, the differences between using Any, and using Count, and why you should consider using Any instead of Count. First of all, let's take a look at my sources of data. I've got a list of string called colors, and I've got a list of doubles that is empty, doesn't contain any items yet. So, if I run…

Contents