What will be printed out as a result of the following program execution?
 
class Program
{ 
    static IEnumerable<char> GetLetters()
    { 
        yield return 'A'; 
        yield return 'B'; 
        yield return 'C'; 
    }
    
    static void Main(string[] args)
    {
       foreach(char ch in GetLetters())
            { 
                  Console.Write(ch);
             }
     }
  }
 
Explanation
GetLetters() function creates an iterator over char type objects.
yield return statement indicates the compiler which value is returned by an iterator on a current iteration. Execution continues from the next operator on the following iteration.
More can be found here: https://msdn.microsoft.com/en-us/library/dscyy5s0.aspx

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты