委托复习

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);
}

posted on 2014-11-19 10:25  Struggling Rookie  阅读(97)  评论(0编辑  收藏  举报