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 }

转载于:https://www.cnblogs.com/hzy3774/archive/2011/11/09/2243650.html

你可能感兴趣的:(c#)