C#委托之泛型委托Func介绍

其定义如下:

public delegate TResult Func<in T1, in T2, out TResult>(T1 arg1, T2 arg2);

 

封装一个具有两个参数并返回 TResult 参数指定的类型值的方法。

示例如下:

   class Program
    {
        static void Main(string[] args)
        {
            Func<int, int, double> funcInt = AddInt;
            Console.WriteLine(funcInt(100, 200));

            Func<string, string, string> funcString = AddString;

            Console.WriteLine(funcString("wang","li"));

            Console.Read();
        }

        public static double AddInt(int x, int y)
        {
            return x + y;
        }

        public static String AddString(String x, String y)
        {
            return x + y;
        }
 
    }

最后运行结果:

 

Come from here:http://www.csharpwin.com/csharpspace/13430r5777.shtml

posted on 2013-06-24 09:57  骄傲的豹子  阅读(203)  评论(0编辑  收藏  举报

导航