Mega Code Archive

 
Categories / C# Tutorial / LINQ
 

Build the necessary Func delegates using anonymous methods

using System; using System.Collections.Generic; using System.Text; using System.Xml.Linq; using System.Linq;     class Program     {         static void Main(string[] args)         {             string[] currentVideoGames = {"test", "this is a test", "asdf", "game 1","game 2", "game 3"};             Func<string, bool> searchFilter = delegate(string game) { return game.Length > 6; };             Func<string, string> itemToProcess = delegate(string s) { return s; };             var subset = currentVideoGames                 .Where(searchFilter).OrderBy(itemToProcess).Select(itemToProcess);             // Print out the results.             foreach (var game in subset)                 Console.WriteLine("Item: {0}", game);         }     }