C#中delegate的简单使用

 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace Demo
7 {
8 public delegate int Fun(int i);
9 class Program
10 {
11 static void Main(string[] args)
12 {
13 Fun f = sqrt;
14 Console.WriteLine(f(5));
15 f = cube;
16 Console.WriteLine(f(5));
17 Console.ReadKey();
18 }
19
20 static int sqrt(int x)
21 {
22 return x * x;
23 }
24
25 static int cube(int x)
26 {
27 return x * x * x;
28 }
29 }
30 }
posted @ 2011-11-09 21:23  丛林听雨  阅读(259)  评论(0编辑  收藏  举报