C# এ Array.GetEnumerator() পদ্ধতিটি অ্যারের জন্য একটি IEnumerator ফেরত দিতে ব্যবহৃত হয়।
সিনট্যাক্স
নিচের সিনট্যাক্স −
public virtual System.Collections.IEnumerator GetEnumerator ();
উদাহরণ
আসুন এখন Array.GetEnumerator() পদ্ধতি −
বাস্তবায়নের একটি উদাহরণ দেখিusing System;
using System.Collections;
public class Demo{
public static void Main(){
int j = 0;
Console.WriteLine("Array elements...");
string[] arr = { "car", "bike", "truck", "bus"};
for (int i = 0; i < arr.Length; i++){
Console.Write("{0} ", arr[i]);
}
Console.WriteLine();
IEnumerator newEnum = arr.GetEnumerator();
Console.WriteLine("IEnumerator for the Array...");
while ((newEnum.MoveNext()) && (newEnum.Current != null)) {
Console.WriteLine("[{0}] {1}", j++, newEnum.Current);
}
}
} আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেArray elements... car bike truck bus IEnumerator for the Array... [0] car [1] bike [2] truck [3] bus