एक सरणी सेट करें:
int[] arr = { 23, 66, 96, 110 };
अब, एक नई सूची बनाएं:
var list = new List<int>();
सरणी तत्वों को सूची में जोड़ने के लिए Add विधि का उपयोग करें:
for (int i = 0; i < arr.Length; i++) {
list.Add(arr[i]);
}
निम्न पूरा कोड है:
उदाहरण
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);
}
}
}
आउटपुट
23 66 96 110