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

S.J. Jason Liu
3 min readOct 7, 2021

--

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.

Any

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

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

And the result would be the same.

Distinct

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.

--

--

S.J. Jason Liu

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