उदाहरण 1: StringCollection में एक तत्व डालना
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringCollection strCol = new StringCollection();
strCol.Add("Accessories");
strCol.Add("Books");
strCol.Add("Electronics");
Console.WriteLine("StringCollection तत्व...");
foreach (string res in strCol) {
Console.WriteLine(res);
}
strCol.Insert(2, "Headphone");
Console.WriteLine("StringCollection तत्व... अपडेटेड");
foreach (string res in strCol) {
Console.WriteLine(res);
}
}
}
आउटपुट
StringCollection तत्व...
Accessories
Books
Electronics
StringCollection तत्व... अपडेटेड
Accessories
Books
Headphone
Electronics
उदाहरण 2: एकाधिक तत्व डालना
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringCollection strCol = new StringCollection();
strCol.Add("Laptop");
strCol.Add("Desktop");
strCol.Add("Tablet");
strCol.Add("Speakers");
Console.WriteLine("StringCollection तत्व...");
foreach (string res in strCol) {
Console.WriteLine(res);
}
strCol.Insert(2, "Headphone");
strCol.Insert(3, "Alienware");
Console.WriteLine("StringCollection तत्व... अपडेटेड");
foreach (string res in strCol) {
Console.WriteLine(res);
}
strCol.Insert(4, "E-Book Reader");
strCol.Insert(5, "Monitor");
strCol.Insert(6, "HDD");
strCol.Insert(7, "SSD");
Console.WriteLine("StringCollection तत्व... अपडेटेड");
foreach (string res in strCol) {
Console.WriteLine(res);
}
}
}
आउटपुट
StringCollection तत्व...
Laptop
Desktop
Tablet
Speakers
StringCollection तत्व... अपडेटेड
Laptop
Desktop
Headphone
Alienware
Tablet
Speakers
StringCollection तत्व... अपडेटेड
Laptop
Desktop
Headphone
Alienware
E-Book Reader
Monitor
HDD
SSD
Tablet
Speakers