Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 7. Extending LINQ to Objects > Writing a Sequence Operator

Writing a Sequence Operator

The role of a sequence operator is to return an IEnumerable<T> sequence based on the elements of a source sequence that have been reordered, filtered, or transformed in some way. The Where and Select standard query operators are examples of sequence operators.

Sequence operators make use of the yield return and yield break keywords introduced in C# 2.0. They enable you to write code that implements an iterator pattern, which allows consumers to use the familiar foreach pattern (the foreach uses the IEnumerable interface methods, GetEnumerator and MoveNext, behind the scenes; you can call these methods directly to gain a small performance improvement if necessary).


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint