Member-only story

C# Programming Language: Lists

Jesse L
5 min readApr 27, 2022

--

Hi everyone, welcome back. In this tutorial, we will be going over Lists in C#. Lists can be used to store a collection of data, similar to that of an array. The key difference between a List and an array is that a List is resizable and an array is not. This leaves the List as a great option when wanting to modify a collection of data. With this introduction out of the way, let’s get into it.

Creating List

Let’s start by creating a List. Before we can create the List, we need to make sure we have our List import, which is included within the System.Collections.Generic package:

using System.Collections.Generic;

Now, we can successfully create our List:

List<int> myList = new List<int>();

So now, we have successfully created our List variable of the integer type named myList. When we create our List, we need to specify the data type. As we can see in the example above, we have used the ‘int’ data type. We can use other data types as well, such as the string or boolean data types.

Adding Elements Into The List

Now, let’s try to add elements into our List. We can do this by using the built in Add() function that is provided. Let’s see an example:

--

--

Jesse L
Jesse L

Written by Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.

No responses yet