• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
gooliugle
博客园    首页    新随笔    联系   管理    订阅  订阅
委托的简单使用
代码
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 
 5 namespace SimpleDelegate
 6 {
 7     public delegate int DelegateTest(int x,int y);
 8     class Program
 9     {
10         static void Main(string[] args)
11         {
12             DelegateTest one = new DelegateTest(SimpleTest.Add);
13             Console.WriteLine("10+10={0}",one(10,10));
14             DelegateTest two = new DelegateTest(SimpleTest.Sub);
15             Console.WriteLine("10-10={0}", two(10, 10));
16             Console.ReadLine();
17         }
18     }
19     public class SimpleTest
20     {
21         public static int Add(int x,int y)
22         {
23             return x + y;
24         }
25         public static int Sub(int x, int y)
26         {
27             return x - y;
28         }
29     }
30 }


posted on 2010-06-21 16:51  gooliugle  阅读(336)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3