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.

--

--

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