日期:2014-05-17  浏览次数:20957 次

C#中delegate使用

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

namespace Demo
{
    public delegate int Fun(int i);
    class Program
    {
         static void Main(string[] args)
        {
            Fun f = sqrt;
            Console.WriteLine(f(5));
            f = cube;
            Console.WriteLine(f(5));
            Console.ReadKey();
        }

        static int sqrt(int x)
        {
            return x * x;
        }

        static int cube(int x)
        {
            return x * x * x;
        }
    }
}
?