How to Convert Integer Array to List in C#?
Last Updated :
15 Jul, 2025
We have given a integer array arr and the task is to convert integer array into the list lst in C#. In order to do this task, we have the following methods:
Method 1: List<T> class: This represents the list of objects which can be accessed by index. It comes under the System.Collection.Generic namespace. List<T> class also provides the methods to search, sort, and manipulate lists. And this is also used to convert a given an integer array to the list .
Syntax:
List<int> lst = new List<int> { 1, 2, 3};
Example:
C#
// C# program to convert a
// given an integer array
// to the list
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
public class GFG{
static void Main(string[] args)
{
// given integer array
// { 10, 20, 30, 40, 50 }
// using List<T> class
List<int> lst = new List<int> { 10, 20, 30, 40, 50 };
// you can write the above line of code as
// int[] ints = new [] { 10, 20, 30, 40, 50 };
// List<int> lst = ints.OfType<int>().ToList();
// printing output
foreach (int i in lst)
{
Console.Write(i + " ");
}
}
}
Output:
10 20 30 40 50
Method 2: List<T>(IEnumerable<T>) Constructor : Using this constructor a new instance of the List<T> class can be initialize that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied. Thus this can also be used to convert a given an integer array to the list .
Syntax:
List<int> lst = new List<int>(integer_array);
Example:
C#
// C# program to convert a
// given an integer array
// to the list
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
public class GFG{
static List<int> get_list(int[] arr)
{
// List<T>(IEnumerable<T>)
// Constructor
// is a used to convert a
// given an integer array
// to the list
List<int> L = new List<int> (arr);
return L;
}
static void Main(string[] args)
{
// given integer array
int[] arr = { 10, 20, 30, 40, 50 };
// function calling
List<int> lst = get_list(arr);
// printing output
foreach (int i in lst)
{
Console.Write(i + " ");
}
}
}
Output:
10 20 30 40 50
Method 3: AddRange(IEnumerable<T>) Method : This method is used to add the elements of the specified collection to the end of the List<T>. Thus this can also be used to convert a given an integer array to the list.
Syntax:
List<int> lst = new List<int>();
lst.AddRange(integer_array)
Example:
C#
// C# program to convert a
// given an integer array
// to the list
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
public class GFG{
static List<int> get_list(int[] arr)
{
// AddRange(IEnumerable<T>)
// Method is a used to convert
// given an integer array
// to the list
List<int> L = new List<int>();
L.AddRange(arr);
return L;
}
static void Main(string[] args)
{
// given integer array
int[] arr = { 10, 20, 30, 40, 50 };
// function calling
List<int> lst = get_list(arr);
// printing output
foreach (int i in lst)
{
Console.Write(i + " ");
}
}
}
Output:
10 20 30 40 50
Method 4: ToList() Method: The Enumerate.Tolist method is from System.Linq Namespace which creates a List<T> from an IEnumerable<T>. It returns a List<T> that contains elements from the input sequences.
Syntax:
List<int> lst = integer_array.ToList();
Example:
C#
// C# program to convert a
// given an integer array
// to the list
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
public class GFG{
static List<int> get_list(int[] arr)
{
// ToList() Method is a used
// to convert a given an
// integer array to the list
List<int> L = arr.ToList();
return L;
}
static void Main(string[] args)
{
// given integer array
int[] arr = { 10, 20, 30, 40, 50 };
// function calling
List<int> lst = get_list(arr);
// printing output
foreach (int i in lst)
{
Console.Write(i + " ");
}
}
}
Output:
10 20 30 40 50
Method 5: Add() Method : This method is used to add an object to the end of the List. Thus this can also be used to convert a given an integer array to the list .
Syntax:
List<int> lst = new List<int>();
lst.Add(int val);
Example:
C#
// C# program to convert a
// given an integer array
// to the list
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
public class GFG{
static List<int> get_list(int[] arr)
{
// Add() Method is a used
// to convert a given an
// integer array to the list
List<int> L = new List<int>();
for(int i = 0 ; i < arr.Length ; i++)
{
L.Add(arr[i]);
}
return L;
}
static void Main(string[] args)
{
// given integer array
int[] arr = { 10, 20, 30, 40, 50 };
// function calling
List<int> lst = get_list(arr);
// printing output
foreach (int i in lst)
{
Console.Write(i + " ");
}
}
}
Output:
10 20 30 40 50
Similar Reads
How to create the ArrayList in C# ArrayList() constructor is used to initialize a new instance of the ArrayList class which will be empty and will have the default initial capacity. ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dyn
2 min read
C# | Convert Queue To array Queue represents a first-in, first out collection of object. It is used when you need a first-in, first-out access of items. When you add an item in the list, it is called enqueue, and when you remove an item, it is called deque. Queue.ToArray Method is used to copy the Queue elements to a new array
2 min read
C# | Convert Stack to array Stack represents a last-in, first out collection of object. It is used when you need a last-in, first-out access of items. When you add an item in the list, it is called pushing the item and when you remove it, it is called popping the item. Stack<T>.ToArray Method is used to copy a Stack<T
2 min read
C# | How to convert an ArrayList to Array In C#, an array is a group of like-typed variables that are referred to by a common name. And each data item is called an element of the array. The data types of the elements may be any valid data type like char, int, float etc. and the elements are stored in a contiguous location.ArrayList represen
4 min read
How to Count Elements in C# Array? To count the number of elements in the C# array, we can use the count() method from the IEnumerable. It is included in the System.Linq.Enumerable class. The count method can be used with any type of collection such as an array, ArrayList, List, Dictionary, etc. Syntax: Count<TSource>() This me
3 min read
C# | Copying the Collection<T> elements to an array Collection<T>.CopyTo(T[], Int32) method is used to copy the entire Collection<T> to a compatible one-dimensional Array, starting at the specified index of the target array. Syntax: public void CopyTo (T[] array, int index); Parameters: array : The one-dimensional Array that is the destin
3 min read