उदाहरण 1: स्ट्रिंग सरणी को List में निर्दिष्ट इंडेक्स पर डालना
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(String[] args) {
string[] strArr = { "John", "Tom", "Kevin", "Mark", "Gary" };
List list = new List(strArr);
Console.WriteLine("List में तत्व...");
foreach(string str in list) {
Console.WriteLine(str);
}
strArr = new string[] { "Demo", "Text" };
Console.WriteLine("रेंज में नए तत्व डालना...");
list.InsertRange(3, strArr);
foreach(string res in list) {
Console.WriteLine(res);
}
}
}
आउटपुट
List में तत्व...
John
Tom
Kevin
Mark
Gary
रेंज में नए तत्व डालना...
John
Tom
Kevin
Demo
Text
Mark
Gary
उदाहरण 2: पूर्णांक सरणी को List में डालना
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(String[] args) {
int[] intArr = { 10, 20, 30, 40, 50 };
List list = new List(intArr);
Console.WriteLine("List में तत्व...");
foreach(int i in list) {
Console.WriteLine(i);
}
intArr = new int[] { 300, 400, 500 };
Console.WriteLine("रेंज में नए तत्व डालना...");
list.InsertRange(2, intArr);
foreach(int res in list) {
Console.WriteLine(res);
}
}
}
आउटपुट
List में तत्व...
10
20
30
40
50
रेंज में नए तत्व डालना...
10
20
300
400
500
30
40
50