Вопрос

I am confused about GetEnumerator method execution. I want to know at what point GetEnumberator method executes. I have a class A and it has 2 or 3 properties and and one of these properties is being used in GetENumerator method. If I assign a new value to that property of an object of class A and then assign same object to some veritable. Then I can see the change ResultView values. It means that when I assign that object then GetEnumerator method executes in back end. Please clarify me if I am wrong.

Это было полезно?

Решение

GetEnumerator is called when the instance is being enumerated. Usually, this is at the start of a foreach clause, and very often in LINQ.

In the debugger, this is also called when you expand the results view on the instance, as you've just found out. It even warns you it will do this. So no, it doesn't get called when you change the property - it only gets called when you start reading the enumerable again - which you're doing in the debugger itself.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top