C# LINQ — “Contains”

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

Vincent Taylor
Dec 16, 2021

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

The Contains Method:

Similar to the Any keyword, the Contains 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.

An Example:

Note: “_names1” is an array. Lists have their own non-LINQ Contains method

Using LINQ Contains allows for the code to be simplified and reduces line count. The Contains method is a more appropriate way to find out if a collection contains a value compared to the Any method.

The Syntax:

--

--

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.