码迷,mamicode.com
首页 > 其他好文 > 详细

委托复习

时间:2014-11-19 12:16:28      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:io   ar   os   sp   on   cti   ad   as   line   

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

委托复习

标签:io   ar   os   sp   on   cti   ad   as   line   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!