Examveda

What will be the output of the following C# code snippet?
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 A, B, C, D

Answer: Option D


This Question Belongs to C Sharp Programming >> Miscellaneous In C Sharp

Join The Discussion

Related Questions on Miscellaneous in C Sharp