Delegate targets : select « LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

    class MainClass
    {
        public static void Main()
        {
            string[] currentVideoGames = {"Shooting", "D","Half Life", "F.E.A.R.","Game", "System"};
            Func<string, bool> searchFilter = new Func<string, bool>(Filter);
            Func<string, string> itemToProcess = new Func<string,string>(ProcessItem);

            var subset = currentVideoGames.Where(searchFilter).OrderBy(itemToProcess).Select(itemToProcess);
            foreach (var game in subset)
                Console.WriteLine("Item: {0}", game);
        }
        public static bool Filter(string s) {return s.Length > 6;}
        public static string ProcessItem(string s) { return s; }
    }








22.63.select
22.63.1.Query Reuse
22.63.2.Select array item by type
22.63.3.Use LINQ with Dictionary
22.63.4.Use LINQ to query characters in a string
22.63.5.Transformation: link two array.
22.63.6.Select with Anonymous Types: prints uppercase and lowercase versions of each string in an input array
22.63.7.Select with Anonymous Types: iterates over each element to print the element's name
22.63.8.Select with Anonymous Types: prints the name of every product in the product list along with the category of the product and its unit price
22.63.9.Using select to create a sequence of each product name.
22.63.10.Converting an Array of Strings to Integers
22.63.11.Converting an Array of Strings to Integers and Sorting It
22.63.12.Query with Intentional Exception Deferred Until Enumeration
22.63.13.Demonstrating the Query Results Changing Between Enumerations
22.63.14.Returning a List
22.63.15.Select Distinct
22.63.16.Select all from a List
22.63.17.Select only pet name
22.63.18.Select sum value
22.63.19.Delegate targets
22.63.20.Adding new line character to selected value