I am trying to understand how yield works in C#. For testing I made some example code:
using System; using System.Text; namespace ConsoleApplication1 { class GameFrame { }; class GameState { public static GameFrame Begin() { Console.WriteLine("GameState.Begin"); return new GameFrame(); } public static GameFrame Play() { Console.WriteLine("GameState.Play"); return new GameFrame(); } public static System.Collections.Generic.IEnumerator<GameFrame> MainLoop() { yield return Begin(); while (true) { yield return Play(); } } }; class Program { static void Main() { while (GameState.MainLoop() != null) { } } } } This code only tries to run once Begin function and call infinite times function Play. Please tell me why I never see my messages in console?