class App
{
static void Main()
{
GameMoves game = new GameMoves();
}
}
public class GameMoves
{
private IEnumerator cross;
private IEnumerator circle; public GameMoves()
{
cross = Cross();
circle = Circle();
} private int move = 0; public IEnumerator Cross()
{
while (true)
{
Console.WriteLine("Cross, move {0}", move);
move++;
if (move > 9)
yield break;
yield return circle;
}
} public IEnumerator Circle()
{
while (true)
{
Console.WriteLine("Circle, move {0}", move);
move++;
if (move > 9)
yield break;
yield return cross;
}
}
}调试的时候发现,构造函数 GameMoves()直接跳过了,求解释
{
static void Main()
{
GameMoves game = new GameMoves();
}
}
public class GameMoves
{
private IEnumerator cross;
private IEnumerator circle; public GameMoves()
{
cross = Cross();
circle = Circle();
} private int move = 0; public IEnumerator Cross()
{
while (true)
{
Console.WriteLine("Cross, move {0}", move);
move++;
if (move > 9)
yield break;
yield return circle;
}
} public IEnumerator Circle()
{
while (true)
{
Console.WriteLine("Circle, move {0}", move);
move++;
if (move > 9)
yield break;
yield return cross;
}
}
}调试的时候发现,构造函数 GameMoves()直接跳过了,求解释
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货