C# में ArrayList से किसी विशिष्ट एलिमेंट को हटाने के लिए Remove() मेथड का उपयोग किया जाता है। यह मेथड पहली बार मिलने वाले निर्दिष्ट ऑब्जेक्ट को ArrayList से हटा देता है।
उदाहरण
using System;
using System.Collections;
class Demo {
static void Main() {
ArrayList arr = new ArrayList();
arr.Add("One");
arr.Add("Two");
arr.Add("Three");
arr.Add("Four");
Console.WriteLine("ArrayList...");
foreach(string str in arr) {
Console.WriteLine(str);
}
// "Three" एलिमेंट को हटाना
arr.Remove("Three");
Console.WriteLine("एलिमेंट हटाने के बाद ArrayList...");
foreach(string str in arr) {
Console.WriteLine(str);
}
Console.ReadLine();
}
}
आउटपुट
ArrayList...
One
Two
Three
Four
एलिमेंट हटाने के बाद ArrayList...
One
Two
Four
नोट: यदि एलिमेंट ArrayList में मौजूद नहीं है, तो Remove() कुछ नहीं करता और कोई एक्सेप्शन भी नहीं फेंकता। इंडेक्स के आधार पर हटाने के लिए RemoveAt() का उपयोग करें।