コード例 #1
0
    static void Main(string[] args)
    {
        Calculate cal = Multiply2;

        cal(3);
        Calculate cal2 = delegate(int num)
        {
            Console.WriteLine("{0} * 2 = {1}", num, num * 2);
        };

        cal2(3);
        Calculate cal3 = (int num) =>
        {
            Console.WriteLine("{0} * 2 = {1}", num, num * 2);
        };

        cal3(3);
        Calculate cal4 = (num) =>
        {
            Console.WriteLine("{0} * 2 = {1}", num, num * 2);
        };

        cal4(3);
        Calculate cal5 = num =>
        {
            Console.WriteLine("{0} * 2 = {1}", num, num * 2);
        };

        cal5(3);
        Calculate2 cal6 = num => { return(num * 2); };

        Console.WriteLine("{0}", cal6(4));
        Calculate2 cal7 = num => num * 2;;

        Console.WriteLine("{0}", cal7(5));
    }
コード例 #2
0
 static void Calc <T>(T a, T b, Calculate2 <T> CalcFunc)
 {
     Console.WriteLine("static void Calc<T>(T a, T b, Calculate2<T> CalcFunc)");
     Console.WriteLine(CalcFunc(a, b));
 }