`
hzy3774
  • 浏览: 985792 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

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;
        }
    }
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics