Wat*_* v2 8 c# linq ienumerator enumerator visual-studio
假设你为下面的代码编写了一个自定义枚举器:
public class School : IEnumerable<Student>
Run Code Online (Sandbox Code Playgroud)
然后在客户端代码中,您执行了以下操作:
static void Main(string[] args)
{
var school = CreateSchoolWithStudents();
var query = from student in school
where student.Name.StartsWith("S")
select student;
Debugger.Break();
}
private static School CreateSchoolWithStudents()
{
return new School
{
new Student { Name = "Sathyaish" },
new Student { Name = "John" },
new Student { Name = "Carol" },
new Student { Name = "Peter" }
};
}
Run Code Online (Sandbox Code Playgroud)
然后,在类的MoveNext方法实现上设置一个断点StudentEnumerator.
然后,当您运行代码并且在构造查询/ IEnumerable之后调试器中断,并且您Results View在下面显示的图片中展开了类似内容时,Visual Studio如何评估序列而不会破坏其枚举器MoveNext?
我一直很好奇这个.
