কম্পিউটার

C# এ ArrayList এর নির্দিষ্ট সূচকে উপাদানটি সরান


অ্যারেলিস্টের নির্দিষ্ট সূচীতে উপাদানটি সরাতে, কোডটি নিম্নরূপ -

উদাহরণ

using System;
using System.Collections;
public class Demo {
   public static void Main(String[] args) {
      ArrayList list1 = new ArrayList();
      list1.Add("A");
      list1.Add("B");
      list1.Add("C");
      list1.Add("D");
      list1.Add("E");
      list1.Add("F");
      list1.Add("G");
      list1.Add("H");
      list1.Add("I");
      Console.WriteLine("Elements in ArrayList1...");
      foreach (string res in list1) {
         Console.WriteLine(res);
      }
      ArrayList list2 = new ArrayList();
      list2.Add("A");
      list2.Add("B");
      list2.Add("C");
      list2.Add("D");
      list2.Add("E");
      list2.Add("F");
      list2.Add("G");
      list2.Add("H");
      list2.Add("I");
      Console.WriteLine("Elements in ArrayList2...");
      foreach (string res in list2)
      {
         Console.WriteLine(res);
      }
      Console.WriteLine("Count of elements in ArrayList2 = " + list2.Count);
      list2.RemoveAt(5);
      Console.WriteLine("Count of elements in ArrayList2 (Updated) = " + list2.Count);
   }
}

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
Elements in ArrayList1...
A
B
C
D
E
F
G
H
I
Elements in ArrayList2...
A
B
C
D
E
F
G
H
I
Count of elements in ArrayList2 = 9
Count of elements in ArrayList2 (Updated) = 8

উদাহরণ

আসুন আরেকটি উদাহরণ দেখি -

using System;
using System.Collections;
public class Demo {
   public static void Main(String[] args) {
      ArrayList list1 = new ArrayList();
      list1.Add("Laptop");
      list1.Add("Dektop");
      list1.Add("Wearables");
      list1.Add("Tablet");
      list1.Add("Notebook");
      list1.Add("Ultrabooks");
      Console.WriteLine("Elements in ArrayList1...");
      foreach (string res in list1) {
         Console.WriteLine(res);
      }
      Console.WriteLine("Count of elements in ArrayList = " + list1.Count);
      list1.RemoveAt(2);
      Console.WriteLine("Count of elements in ArrayList (Updated) = " + list1.Count);
   }
}

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
Elements in ArrayList1...
Laptop
Dektop
Wearables
Tablet
Notebook
Ultrabooks
Count of elements in ArrayList = 6
Count of elements in ArrayList (Updated) = 5

  1. C# এ সংগ্রহের নির্দিষ্ট সূচকে উপাদান সরান

  2. C# এ ArrayList থেকে উপাদানের একটি পরিসীমা সরান

  3. C# এ অ্যারেলিস্ট থেকে সমস্ত উপাদান সরান

  4. একটি হ্যাশসেটে C# এ নির্দিষ্ট উপাদান রয়েছে কিনা তা পরীক্ষা করুন