C# LINQ — “Any”

LINQ (Language-Integrated Query) is a set of integrated C# capabilities which allow queries against data.

Today’s Objective: Go over the LINQ Any function used to search a data collection for a specific value/s.

The LINQ Any Method:

Similar to the Contains function, the Any function allows for the searching of a data collection for the existence of a specific data value or condition, returning a boolean if it exists.

Microsoft Documentation

An Example:

As shown in the example above, using LINQ Any is one way to simplify your C# code and minimize your line count.

The Syntax:

Note: “name” can be called whatever you want, just like “nameFound”. Since mine is a string[] of names, “name” is an appropriate variable name.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store