Results 1 to 2 of 2

Thread: Yeild ??

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Yeild ??

    Can anyone tell me what this yield keyword means in the .net framework 2.0 ?

    I'm scared !

    Parksie

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width