For this final post, things get a bit difficult to keep track of. But really all we are doing is... wait, the image below is fantastic. It shows the characters, dream levels, and events that occur in Inception. Rick Slusher created this masterpiece and was recognized for his work here. Kick.

Please start at the beginning of this 8 part series. The answer from part 7 is: 3 4 5.
So all we are doing here is taking the code from post 7, and replacing the implementation of the List() function to utilize the yield-return instead of creating a chunk ram to hold all the return values like we did when we transitioned from post 5 to post 6. We've been here before, but we came through a different door.
class Demo8 // return an enumeration of delegates, that access a modified closure
{
public Demo8()
{
foreach (var myDelegate in List())
{
Console.Write(myDelegate() + " ");
}
Console.WriteLine("");
}
IEnumerable<MyDelegate> List()
{
for (var j = 0; j < 3; j++)
{
yield return delegate { return j++; };
}
}
}
Simple as it looks, I think it would be neat if Rick Slusher could create a diagram for this. Maybe someday I'll give it a try.
If you read the previous 7 posts, then there is absolutely no reason why you cannot answer the question: What is the output of the above? Since there is no post 9 planned, and I don't want to place the answer on the same post as the question, then, I suppose, Cobb's totem just keeps spinning on the desk... wait... did it wobble?
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.