C# LINQ — “Distinct”

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

Vincent Taylor
Dec 17, 2021

Today’s Objective: Use the Distinct LINQ method to create a data value collection of unique elements, and look at a generic C# alternative.

The Distinct Method:

The Distinct method of LINQ allows for the removal of duplicate elements in an array, and returns a new IEnumerable<T> of distinct elements.

Microsoft Documentation

An Example:

The Distinct method is applied to an array via “arrayName.Distinct()”, and returns a new IEnumerable<arrayType> which is the original array, but with all duplicates removed.

The resulting IEnumerable<arrayType> can be used a lot like a variable array, and is able to iterate through all elements in the collection.

The Syntax:

--

--

Vincent Taylor

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