Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press

Buy directly from Paradoxal Press at $33.99 (Save 43%)



Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA


Listing 14-47 extracted from chapter Unsafe code, exceptions, anonymous methods, iterators


Listing 14-46<     > Listing 14-48


This listing can be compiled with the command line:
csc.exe /target:exe Example_14_47.cs
Errors: 0 Warnings: 0


Example_14_47.cs
using System.Collections.Generic;
class Program{
   static public IEnumerable<int> PipelineIntRange( int begin, int end ) {
      System.Diagnostics.Debug.Assert( begin < end );
      for (int = begin; i <= end; i++) {
         System.Console.WriteLine( "Yield:" + i );
         yield return i;
      }
   }
   static public IEnumerable<int> PipelineMultiply( int factor , 
                                               IEnumerable<int> input ) {
      foreach int in input )
         yield return i * factor;
   }
   static public IEnumerable<int> PipelineFilterModulo( int modulo , 
                                               IEnumerable<int> input  ){
      foreach int in input )
         if( i%modulo == )
            yield return i;
   }
   static public IEnumerable<int> PipelineJoin( IEnumerable<int> input1,
                                                IEnumerable<int> input2) {
      foreach int in input1 )
         yield return i;
      foreach int in input2 )
         yield return i;
   }
   static void Main(){
      foreach (int in PipelineJoin( 
         PipelineIntRange(-4, -2), PipelineFilterModulo( 3, 
                                      PipelineMultiply( 2,
                                         PipelineIntRange(110) ) ) ) )
         System.Console.WriteLine(i);
   }
}	
Copyright Patrick Smacchia 2006 2007