Day 12 LINQ Query Operators

Leslie RamĂ­rez
2 min readDec 21, 2021

--

Hello there!! 👋👋👋 It’s our 12th coding winter day. For today let’s talk about some of the cool things we can do with collections using LINQ, specifically the Any() method.

But first Let’s start learning about what is LINQ. Let’s go!

LINQ

or Language Integrated Query is a set of language ad runtime writing structured type-safe queries over local object collections and remote data sources such as tables in SQL server database.

The basic units of data in LINQ are sequences and elements. A sequence is any object that implements IEnumerable<T>, and an element is each item in the sequences.

A query operator is a method that transforms a sequence. in the Enumerable class in System.Linq, there are many query operators, all implemented as static extension methods. Like the one, we are going to focus this time Any().

Any()

Not all the queries operators return a sequence. the element operators extract one element from the input sequence, one example of this is Any. Any is part of the quantifiers that return a bool value.

The Any operator is used to check if the sequence is blank or not. Also, we can check any single element in a sequence satisfy a given condition. For the use of Any operator we can do it with the following syntax:

Example of the first overloaded version of Any operator:

Example of the second overload:

Conclusions

The enumeration of source is stopped as soon as the result can be determined. If you want to learn more about it follow this link:

Enumerable.Any Method (System.Linq) | Microsoft Doc

If you enjoyed this article, please hold down the clap button 👏👏👏 Don’t forget to follow our Coding winter Calendar. Have a wonderful day! 🧡 💛 💚🧡 💛 💚

--

--

Leslie RamĂ­rez

I am Microsoft MVP in the award category: Developers technologies, a professional with several years in software development specifically in .NET technology.