LINQ: Searching in Program Pt.1- C# Skill in Unity: 13

Objective: quick introduction of LINQ of Unity.

LINQ: Language Integrated Query- which is used to searching in program data. Using LINQ well will help you organizing database quicker and properer. Here are some properties to use LINQ.


When searching a specific data in array or list, we might need to create a foreach loop to look up the data. Using “any” would return the result of searching as value bool. But before we using LINQ, we must contain namespace “System.Linq”.

Let’s use foreach loop to create some code that we can use “Any” to improve.

Any” would tell if there is any result matched to request, and we need to use lambda to search in the database.

And we can store the result in a variable to print out.

And the result would be quite obviously.


Contains is pretty much the same as “any” but easier.

And the result would be the same.


The situation of using Distinct is quite different. It would remove the duplicated and restore the list or array as a new one. Which would be handy to remove some duplicated data.

We will run “distinct” with new array data with some duplicated one.

Using “distinct”, you will not need any parameter.

And the result would ignore the duplicated data to print out the distinct.




A passionate gamer whose goal is to work in video game development.

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

Recommended from Medium

Apple Dev Guild Week

Nuke Build — best build automation system

As a Software Engineer, Here Are 7 Books You Should Always Have at Your Desk

Planning observability of your system

What does the developer's survey think about Job Satisfaction?


Async Superpowers: State Machines

Euler’s Identity

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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Local control for Player

C# LINQ — “OrderBy”

How to use Post Processing in Unity