কম্পিউটার

C# এ StringCollection এর মাধ্যমে পুনরাবৃত্তি করে এমন একটি গণনাকারী পান


স্ট্রিংকলেকশনের মাধ্যমে পুনরাবৃত্তি করে এমন একটি গণনাকারী পেতে, কোডটি নিম্নরূপ -

উদাহরণ

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);
   }
}

আউটপুট

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

তৈরি করবে
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

উদাহরণ

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

using System;
using System.Collections.Specialized;
public class Demo {
   public static void Main(){
      StringCollection stringCol = new StringCollection();
      stringCol.Add("10");
      stringCol.Add("20");
      stringCol.Add("30");
      stringCol.Add("40");
      stringCol.Add("50");
      stringCol.Add("60");
      stringCol.Add("70");
      stringCol.Add("80");
      stringCol.Add("90");
      stringCol.Add("100");
      Console.WriteLine("Elements...");
      foreach (string res in stringCol){
         Console.WriteLine(res);
      }
      Console.WriteLine("Iterating through StringCollection with Enumerator...");
      StringEnumerator myenum = stringCol.GetEnumerator();
      while (myenum.MoveNext())
         Console.WriteLine(myenum.Current);
   }
}

আউটপুট

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

তৈরি করবে
Elements...
10
20
30
40
50
60
70
80
90
100
Iterating through StringCollection with Enumerator...
10
20
30
40
50
60
70
80
90
100

  1. C# এ অভিধানের মাধ্যমে পুনরাবৃত্তি করে এমন একটি গণনাকারী পান

  2. 4টি পরিষেবা যা আপনাকে আপনার স্মার্টফোনের মাধ্যমে ট্র্যাক করে

  3. সেই ছবি-নিখুঁত পোস্ট পেতে 5টি দরকারী Instagram টিপস

  4. বিনামূল্যে অ্যাপ যা আপনাকে অর্থ উপার্জন করতে সাহায্য করে