Where can I find out the inputs and outputs of counters in C #?

Is there a good resource that explains the concept of counters and custom counters? In particular, one with a good convincing example of why you would like to implement IEnumerable yourself and how you could use it effectively?

I sometimes meet yield , and I try to better understand it.

+7
c # ienumerable
source share
5 answers

The simplest example:

 IEnumerable<string> GetNames() { yield return "Bob"; yield return "Bob uncle"; yield return "Alice"; yield return "Stacy"; yield return "Stacy mom"; } 

Using:

 foreach (var name in GetNames()) { Console.WriteLine(name); } 

To see it in action, put a debugger breakpoint on each line in the GetNames method.

+8
source share

Another book that I found very useful when I found out about IEnumerable and IEnumerator is Troelsen Pro's C # 2008 book. It explains what interfaces are and how to create iterators with the yield keyword.

I hope for this help.

+3
source share

Here are a few more resources to clean up the basics.

Wes has an excellent article on the characteristics of iterators:

http://blogs.msdn.com/wesdyer/archive/2007/03/23/all-about-iterators.aspx

If you have questions about why there are so many weird restrictions on what you can do in an iterator block, here are my seven series on what motivated unusual rules:

http://blogs.msdn.com/ericlippert/archive/tags/Iterators/default.aspx

+2
source share

The best example and link I found are actually in a C # book in depth from the almighty John Skeet. It is not too expensive and is worth what you learn about C #.

+1
source share

A good example can be found on the MSDN page for IEnumerable .

0
source share

All Articles