I have implemented some functionality in C# using the yield statement with the function returning an IEnumerable.
My question is that if this function is a static function in a static class, does it implicitly hold anything as a state machine that would affect more than one user or does the iterator hold everything relating to the state? (Static members are application wide.)
No it does not. The created
IEnumerable<T>will be of a type which contains no additional static data. It is possible for it to reference static information but only if you explicitly access it from within the iteratorFor example.
Roughly translates into