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 15-24 extracted from chapter Collections


Listing 15-23<     > Listing 16-1


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


Example_15_24.cs
using System;
using System.Collections.Generic;

class Program{
   static public IEnumerable<T> Filter<T> (
                      Predicate<T> predicate, IEnumerable<T> collection) {
      foreach (T item in collection)
         if (predicate(item))
            yield return item;
   }
   static public IEnumerable<T> Transform<T> (
                  Converter<T,T> transformer, IEnumerable<T> collection) {
      foreach (T item in collection)
         yield return transformer(item);
   }
   static public IEnumerable<U> Converter<T, U> (
                   Converter<T, U> converter, IEnumerable<T> collection) {
      foreach (T item in collection)
         yield return converter(item);
   }
   static public IEnumerable<int> PipelineIntRange( int begin, int end ) {
      System.Diagnostics.Debug.Assert( begin < end );
      for int = begin; i <= end; i++ )
         yield return i;
   }
   static void Main() {
      int modulo = 3;
      int factor = 2;
      foreach (string in 
         Converter<int,string>( delegate(int item) { 
            return "Hello:" + item.ToString(); }, 
               Filter( delegate(int item) { 
                  return (item % modulo == 0); },
                     Transform( delegate(int item) { 
                        return item * factor; },
                           PipelineIntRange(110) ) ) ) )
         Console.WriteLine(s);
   }
}	
Copyright Patrick Smacchia 2006 2007