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
Зареєструйся Зараз
або Підпишись на майбутні тести