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.

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.

--

--

--

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

Introduction to Docker Compose

Getting Started with Boto3

Boto Rosa

Senior Developer Skillset

How to Read PDF file using Python

50 Shades of Fibonacci

Okuna Holidays 2019 Update!

Configure NewRelic on Azure AppService

A Web Developer’s Journey 3

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

Unity C#: Static

Building a Modular Ducking System

How to use Post Processing in Unity

Scripting Actions (New Unity Input System)