在下面的代码中,我理解第二个初始化打印一个“外部”和三个“内部”。但是为什么第一个根本不打印,我希望它在“外面”打印一个。
DeferExecution a = new DeferExecution(); // prints nothing
DeferExecution b = new DeferExecution(null); // print one "outside" and three "inside".
class DeferExecution
{
public IEnumerable<string> Input;
public DeferExecution()
{
Input = GetIEnumerable();
}
public DeferExecution(string intput)
{
Input = GetIEnumerable().ToArray();
}
public IEnumerable<string> GetIEnumerable()
{
Console.WriteLine("outside");
var strings = new string[] {"a", "b", "c"};
foreach (var s in strings)
{
Console.WriteLine("inside");
yield return s;
}
}
}