C# LINQ — “Distinct”

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

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:

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to debug like Feynman and Bayes

Simple Python Program To detect Number Plates of the cars and look for their information using RTO…

📢METAWORLD BREAKING NEWS📢

Adventures in Salesforce | Platform events to rescue in asynchronous apex failures

Two examples of DFS/BFS graph traversal

Using Agile Philosophy for Running a Small Business

DigiFabster Product Update: CNC Milling & Lathe, 2D Cutter

How to learn to solve coding interview questions using Leetcode (Part II)

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
Vincent Taylor

Vincent Taylor

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

More from Medium

What Is C# LINQ?

Language-Integrated Queries: LINQ

How to use Post Processing in Unity

Playing With Barbie!