एक सरणी सेट करें -
int[] arr = { 23, 66, 96, 110 }; अब, एक नई सूची बनाएं -
var list = new List<int>();
जोड़ें विधि का उपयोग करें और सरणी तत्वों को सूची में जोड़ें -
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