首页 > 其他 > 详细

委托复习

时间:2014-11-19 12:14:23      阅读:256      评论:0      收藏:0      [点我收藏+]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _02_委托复习 {
class Program {
static void Main(string[] args) {
//无参无返回值
//Mydeligate md = new Mydeligate(SayHi);
//Action ac = new Action(SayHi);
//Mydeligate md = new Mydeligate(() => {
// Console.WriteLine("哈啊哈");
//});
//----------------------------------------
//Mydeligate2 md = new Mydeligate2(Sum);
//Mydeligate2 md = new Mydeligate2((int a, int b) => {
// Console.WriteLine(a * b);
//});
//Mydeligate3 md = new Mydeligate3(GetSum);
//int a= md(5, 3);
//Mydeligate3 md = new Mydeligate3((int a, int b) => {
// return a * b;
//});
//int c = md(5,5);

//Func与Action
//Action表示无返回值
Action ac = new Action(() => {
Console.WriteLine("无参无返回值");
});
ac();
Action<int> ac2 = new Action<int>((int a) => {
Console.WriteLine(a);
});
ac2(2);
Func<int, int, string> fun = new Func<int, int, string>((int b, int c) => (b + c).ToString());
string str = fun(22, 22);
Console.WriteLine(str);
Console.ReadKey();
}
public static void SayHi() {
Console.WriteLine("你好么");
}
public static void Sum(int a, int b) {
Console.WriteLine(a + b);
}
public static int GetSum(int a, int b) {
return a + b;
}
}
public delegate void Mydeligate();
public delegate void Mydeligate2(int a, int b);
public delegate int Mydeligate3(int a, int b);
}

委托复习

原文:http://www.cnblogs.com/DJYBlog/p/4107613.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!