What will be the result of the following code execution?
 
class Program 
{ 
    static IEnumerable<char> GetLetters() 
    { 
         yield return 'A'; 
         yield break; 
         yield return 'B'; 
         yield return 'C'; 
    } 


   static void Main(string[] args) 
   { 
       foreach(char ch in GetLetters()) 
       { 
            Console.Write(ch); 
       } 
       Console.ReadLine(); 
    } 
}
 
Explanation
Yield break operator ends the iteration. Operators yield return 'B' and yield return 'C' will never be executed. Read more there: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/iterators

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести