c# - An example for supporting foreach without implementing IEnumerable -


i looking @ this blog explains foreach can supported without implementing ienumerable. not go details of implementation.

i looking example of how support foreach without implementing ienumerable.

edit: @sam 's comment, got looking for. (see answer below)

here class doesn't implement ienumerable, or interfaces @ all:

public class foo  {     public ienumerator<int> getenumerator()     {         yield return 1;         yield return 2;     } } 

you can foreach so:

foreach (int n in new foo())     console.writeline(n); 

and print:

1
2


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -