Question
What will the given code snippet specify?class MyClass{Â Â char chrs = 'A' ;Â Â public IEnumerator GetEnumerator()Â Â {Â Â Â Â for (int i = 20; i >=0; --i)Â Â Â Â if (i == 10) yield break;Â Â Â Â yield return (char)((chrs + i));Â Â }}class Program{Â Â static void Main(string[] args)Â Â {Â Â Â Â MyClass mc = new MyClass();Â Â Â Â foreach (char ch in mc)Â Â Â Â Console.Write(ch + " ");Â Â Â Â Console.WriteLine();Â Â Â Â Console.ReadLine();Â Â }}
Answer: Option C
Was this answer helpful ?
The code to specify stoppage of the iterator using 'yield break' statement When this statement executes, the iterator signals that the end of the collection has been reached, which effectively stops the iterator.
Output: U T S R Q P O N M L
Was this answer helpful ?
Submit Solution