委托

新建一个wpf程序,窗口中拖进一个Button控件,在控件的点击事件中写下如下代码:

private
void button_Click(object sender, RoutedEventArgs e) { //kk k = new kk(); //AddDelegate ss = new AddDelegate(new kk.Add(1, 2)); AddDelegate soso = new AddDelegate(kk.Add); soso += kk.Delete; soso(1,2); }
新建一个类,再类中写如下代码:

public
class kk { public static void Add(int a, int b) { MessageBox.Show((a + b).ToString()); } public static void Delete(int a, int b) { MessageBox.Show((a - b).ToString()); } }

      图1                         图2                  图3

posted @ 2017-03-23 17:21  中阳里士  阅读(143)  评论(0编辑  收藏  举报