コード例 #1
0
    static void Main(string[] args)
    {
        SimpleDelegate sd = new SimpleDelegate();
        // delegate ساخت نمونه‌اي جديد از
        Comparer cmp = new Comparer(Name.CompareFirstNames);

        Console.WriteLine("\nBefore Sort: \n");
        sd.PrintNames();
        sd.Sort(cmp);
        Console.WriteLine("\nAfter Sort: \n");
        sd.PrintNames();
    }
コード例 #2
0
    static void Main(string[] args)
    {
        SimpleDelegate sd = new SimpleDelegate();

        // this is the delegate instantiation
        Comparer cmp = new Comparer(Name.CompareFirstNames);

        Console.WriteLine("\nBefore Sort: \n");

        sd.PrintNames();

        // observe the delegate argument
        sd.Sort(cmp);

        Console.WriteLine("\nAfter Sort: \n");

        sd.PrintNames();
    }
コード例 #3
0
                public static void MainMethod()
                {
                    var sd = new SimpleDelegate();

                    //To use a delegate, you must create an instance of it.
                    // this is the delegate instantiation
                    Comparer cmp = new Comparer(Name.CompareFirstNames);

                    Console.WriteLine("\nBefore Sort: \n");

                    sd.PrintNames();

                    // observe the delegate argument
                    sd.Sort(cmp);

                    Console.WriteLine("\nAfter Sort: \n");

                    sd.PrintNames();

                    /* The delegate, cmp, is then used as a parameter to the Sort() method, which uses it just like a normal method.
                     * Observe the way the delegate is passed to the Sort() method as a parameter in the code below.
                     *
                     *      sd.Sort(cmp);
                     *
                     * Using this technique, any delegate handler method may be passed to the Sort() method at run-time. i.e.
                     * You could define a method handler named CompareLastNames(), instantiate a new Comparer delegate instance with it,
                     * and pass the new delegate to the Sort() method.
                     */

                    cmp = new Comparer(Name.CompareLastNames);

                    Console.WriteLine("\nBefore Sort: \n");

                    sd.PrintNames();

                    // observe the delegate argument
                    sd.Sort(cmp);

                    Console.WriteLine("\nAfter Sort: \n");

                    sd.PrintNames();
                }
コード例 #4
0
ファイル: SimpleDelegate.cs プロジェクト: csgambone/Tutorial
    static void xMain(string[] args)
    {
        SimpleDelegate sd = new SimpleDelegate();

        // this is the delegate instantiation
        Comparer cmp = new Comparer(Name.CompareFirstNames);

        Console.WriteLine("\nBefore Sort: \n");

        sd.PrintNames();

        // observe the delegate argument
        sd.Sort(cmp);

        Console.WriteLine("\nAfter Sort: \n");

        sd.PrintNames();

        // keep screen from going away
        // when run from VS.NET
        Console.ReadLine();
    }
コード例 #5
0
ファイル: SimpleDelegate.cs プロジェクト: JeremiahZhang/AKA
    static void Main(string[] args)
    {
        SimpleDelegate sd = new SimpleDelegate();

        // this is the delegate instantiation
        Comparer cmp = new Comparer(Name.CompareFirstNames);

        Console.WriteLine("\nBefore Sort: \n");

        sd.PrintNames();

        // observe the delegate argument
        sd.Sort(cmp);

        Console.WriteLine("\nAfter Sort: \n");

        sd.PrintNames();
    }