কম্পিউটার

C# তে সংগ্রহ থেকে বস্তুর প্রথম ঘটনা অপসারণ করা হচ্ছে


সংগ্রহ থেকে বস্তুর প্রথম উপস্থিতি অপসারণ করতে, কোডটি নিম্নরূপ -

উদাহরণ

using System;
using System.Collections.ObjectModel;
public class Demo {
   public static void Main(){
      Collection<string> col = new Collection<string>();
      col.Add("Andy");
      col.Add("Kevin");
      col.Add("John");
      col.Add("Nathan");
      col.Add("Nathan");
      col.Add("Katie");
      col.Add("Barry");
      col.Add("Nathan");
      col.Add("Mark");
      Console.WriteLine("Count of elements = "+ col.Count);
      Console.WriteLine("Iterating through the collection...");
      var enumerator = col.GetEnumerator();
      while (enumerator.MoveNext()) {
         Console.WriteLine(enumerator.Current);
      }
      col.Remove("Nathan");
      Console.WriteLine("Count of elements (updated) = "+ col.Count);
      Console.WriteLine("Iterating through the collection... (updated)");
      enumerator = col.GetEnumerator();
      while (enumerator.MoveNext()) {
         Console.WriteLine(enumerator.Current);
      }
   }
}

আউটপুট

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

তৈরি করবে
Count of elements = 9
Iterating through the collection... Andy
Kevin
John
Nathan
Nathan
Katie
Barry
Nathan
Mark
Count of elements (updated) = 8 
Iterating through the collection... (updated)
Andy
Kevin
John
Nathan
Katie
Barry
Nathan
Mark

উদাহরণ

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

using System;
using System.Collections.ObjectModel;
public class Demo {
   public static void Main(){
      Collection<string> col = new Collection<string>();
      col.Add("One");
      col.Add("Two");
      col.Add("Two");
      col.Add("Four");
      col.Add("Five");
      col.Add("Two");
      col.Add("Six");
      col.Add("Seven");
      Console.WriteLine("Count of elements = "+ col.Count);
      Console.WriteLine("Iterating through the collection...");
      var enumerator = col.GetEnumerator();
      while (enumerator.MoveNext()) {
         Console.WriteLine(enumerator.Current);
      }
      col.Remove("Two");
      Console.WriteLine("Count of elements = "+ col.Count);
      Console.WriteLine("Iterating through the collection... (updated)");
      enumerator = col.GetEnumerator();
      while (enumerator.MoveNext()) {
         Console.WriteLine(enumerator.Current);
      }
   }
}

আউটপুট

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

তৈরি করবে
Count of elements = 8
Iterating through the collection...
One
Two
Two
Four
Five
Two
Six
Seven
Count of elements = 7
Iterating through the collection... (updated)
One
Two
Four
Five
Two
Six
Seven

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

  2. একটি উপাদান C# এর সংগ্রহে আছে কিনা তা পরীক্ষা করুন

  3. C# এ স্ট্রিংডিকশনারি থেকে সমস্ত এন্ট্রি মুছে ফেলা হচ্ছে

  4. C# এ সংগ্রহ থেকে উপাদান পুনরুদ্ধার করা হচ্ছে