Demystifying the C# Yield-Return Mechanism

In the current February 2012 issue of Visual Studio Magazine, I wrote an article titled “Demystifying the C# Yield-Return Mechanism”. My article starts:

I remember when the C# language yield-return statement was released as part of C# 2.0 along with Visual Studio 2005. Early documentation for the yield-return mechanism made the statement sound exotic and mysterious.   Recent discussions with some of my developer colleagues suggested that several years later now the yield-return statement isn’t used very often. We suspect this lack of use is not so much because developers don’t know how to use the yield-return mechanism, but rather mostly because developers aren’t quite sure exactly when to use yield-return. In this article I’ll describe three common programming scenarios where you might want to consider using yield-return:    1. Generating a sequence of strings where each string in the sequence depends on the value of the previous string. 2. Processing a text file sequentially where different kinds of lines are treated differently. 3. Sequentially filtering or modifying a large List collection of objects.

You can read the rest of the article online at http://visualstudiomagazine.com/articles/2012/02/01/demystifying-the-c-yield-return-mechanism.aspx

About these ads
This entry was posted in Software Test Automation. Bookmark the permalink.