Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# program to convert an array to an ordinary list with the same items
Set an array −
int[] arr = { 23, 66, 96, 110 };
Now, create a new list −
var list = new List<int>();
Use the Add method and add the array elements to the list −
for (int i = 0; i < arr.Length; i++) {
list.Add(arr[i]);
}
The following is the complete code −
Example
using System;
using System.Collections.Generic;
public class Program {
public static void Main() {
int[] arr = { 23, 66, 96, 110 };
var list = new List<int>();
for (int i = 0; i < arr.Length; i++) {
list.Add(arr[i]);
}
foreach(int res in list) {
Console.WriteLine(res);
}
}
}
Output
23 66 96 110
Advertisements
