15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

enumerations ❘ 143<br />

public class HelloCollection<br />

{<br />

public IEnumerator GetEnumerator()<br />

{<br />

return new Enumerator(0);<br />

}<br />

public class Enumerator: IEnumerator, IEnumerator, IDisposable<br />

{<br />

private int state;<br />

private string current;<br />

public Enumerator(int state)<br />

{<br />

this.state = state;<br />

}<br />

bool System.Collections.IEnumerator.MoveNext()<br />

{<br />

switch (state)<br />

{<br />

case 0:<br />

current = "Hello";<br />

state = 1;<br />

return true;<br />

case 1:<br />

current = "World";<br />

state = 2;<br />

return true;<br />

case 2:<br />

break;<br />

}<br />

}<br />

return false;<br />

}<br />

}<br />

void System.Collections.IEnumerator.Reset()<br />

{<br />

throw new NotSupportedException();<br />

}<br />

string System.Collections.Generic.IEnumerator.Current<br />

{<br />

get<br />

{<br />

return current;<br />

}<br />

}<br />

object System.Collections.IEnumerator.Current<br />

{<br />

get<br />

{<br />

return current;<br />

}<br />

}<br />

void IDisposable.Dispose()<br />

{<br />

}<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!