Grab a List- C# Skill in Unity: 6

Objective: get to know about the basic of list in C#.

Photo by Kelly Sikkema on Unsplash

List is a function that similar to array but available to add and remove a new item, or doing any other actions during runtime.

Take an example from RPG game, array can be used to fixed numbers of item such as inventory. List can be used to the whole item library due to its flexibility.

How to use list

List can be created as a variable and readjusted in editor.
To create a list, you need to declare a type to it.

Then we can add some elements by using List.Add(item), and pass it the value that match the type.

If you want to insert an value to a specific position or index, just use List.Insert(int, item).

We can also remove some elements that we do not need by using List.Remove(item). You can use the value or index to locate the specific element.

The last, to remove the whole list, we can use List.Clear() to clear everything.

List is very similar to array but with more functionality and usage in program.
That is pretty much everything you need to know about the list of Unity.

--

--

--

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

Exam DP-203: Data Engineering on Microsoft Azure replaces both Exam DP-200 and Exam DP-201

Monolithic Architecture

There is Always a Day One! Can I be a Perfect Programmer ?

Perl vs Python | Major Differences Everyone Should Know

IVR Service for Call Centers

Bag of Tokens

7 ways to become a better developer

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

How to use Post Processing in Unity

Unity Dev Blog: Adjusting Gameplay Mechanics

Making Tic Tac Toe Using Unity 2D and C#

Creating An Advanced 2D Player Controller Without Any Unity Components! (Part 2)