What will be the output of the following C# code snippet? [code] class MyClass { char[] chrs = { 'A', 'B', 'C', 'D' }; public

Daniel William

New member
What will be the output of the following C# code snippet?
Code:
 class MyClass
 {
     char[] chrs = { 'A', 'B', 'C', 'D' };
     public System.Collections.IEnumerator GetEnumerator()
     {
         foreach (char ch in chrs)
         yield return ch;
     }
 }
 class Program
 {
     static void Main(string[] args)
     {
         MyClass mc = new MyClass();
         foreach (char ch in mc)
         Console.Write(ch + " ");
         Console.WriteLine();
         Console.ReadLine();
     }
 }
A. Run time error
B. Compile time error
C. Code runs successfully prints nothing
D. Code runs successfully prints
Code:
 A, B, C, D
 

Tìm kiếm

Back
Top