|
-
Nov 13th, 2006, 08:50 AM
#1
Thread Starter
Fanatic Member
Yeild ??
Can anyone tell me what this yield keyword means in the .net framework 2.0 ?
I'm scared !
-
Nov 13th, 2006, 09:03 AM
#2
Re: Yeild ??
Yield is used to simplify implementing implementing iterators.
Pre C# 2.0 you would need to implement both IEnumerable on your class and IEnumerator on a custom enumerator object. Since this is tedious and repetetive, in C# 2.0 you can make an "iterator block" which encapsulates the iteration process.
Using "yield" within a loop in your iterator block "pauses" the loop and returns a value. Movement within the loop itself is managed for you. In effect it's a sort of declarative form of IEnumerator.
There is an example on the MSDN page for "yield".
http://msdn2.microsoft.com/en-us/library/9k7k7cf0.aspx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|