কম্পিউটার

C# এ সংগ্রহে নির্দিষ্ট বস্তুর সূচক অনুসন্ধান করা হচ্ছে


সংগ্রহে নির্দিষ্ট বস্তুর সূচক অনুসন্ধান করতে, কোডটি নিম্নরূপ -

উদাহরণ

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");
      strCol.Add("Books");
      Console.WriteLine("StringCollection elements...");
      foreach (string res in strCol) {
         Console.WriteLine(res);
      }
      strCol.Insert(2, "Headphone");
      Console.WriteLine("StringCollection elements...UPDATED");
      foreach (string res in strCol) {
         Console.WriteLine(res);
      }
      Console.WriteLine("Index of specific object Electronics? = "+strCol.IndexOf("Electronics"));
   }
}

আউটপুট

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

তৈরি করবে
StringCollection elements...
Accessories
Books
Electronics
Books
StringCollection elements...UPDATED
Accessories
Books
Headphone
Electronics
Books
Index of specific object Electronics? = 3

উদাহরণ

এখন আরেকটি উদাহরণ দেখা যাক -

using System;
using System.Collections.Specialized;
public class Demo {
   public static void Main() {
      StringCollection stringCol = new StringCollection();
      String[] arr = new String[] { "100", "200", "300", "400", "500" };
      Console.WriteLine("Array elements...");
      foreach (string res in arr) {
         Console.WriteLine(res);
      }
      stringCol.AddRange(arr);
      Console.WriteLine("Does the specified string is in the StringCollection? = "+stringCol.Contains("800"));
      Console.WriteLine("Total number of elements = "+stringCol.Count);
      Console.WriteLine("Iterating through StringCollection = "+stringCol.Count);
      StringEnumerator myenum = stringCol.GetEnumerator();
      while (myenum.MoveNext())
      Console.WriteLine(myenum.Current);
      Console.WriteLine("Index of specific object 500? = "+stringCol.IndexOf("500"));
      Console.WriteLine("Index of specific object 1000? = "+stringCol.IndexOf("1000"));
   }
}

আউটপুট

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

তৈরি করবে
Array elements...
100
200
300
400
500
Does the specified string is in the StringCollection? = False
Total number of elements = 5
Iterating through StringCollection = 5
100
200
300
400
500
Index of specific object 500? = 4
Index of specific object 1000? = -1

  1. C# এ একটি সাজানো তালিকার নির্দিষ্ট সূচক থেকে সরান

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

  3. একটি SortedSet বস্তু C# এ নির্দিষ্ট সংগ্রহের একটি যথাযথ সুপারসেট কিনা তা পরীক্ষা করুন

  4. একটি SortedSet বস্তু C# এ নির্দিষ্ট সংগ্রহের একটি সঠিক উপসেট কিনা তা পরীক্ষা করুন