博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CLR Via CSharp----------Delegate&Lambda
阅读量:4622 次
发布时间:2019-06-09

本文共 1805 字,大约阅读时间需要 6 分钟。

CLR Via CSharp----------Delegate&Lambda

 

1. There are some simple samples of how to use the delegate。

1     class Program 2     { 3         static void Main(string[] args) 4         { 5  6             String[] names = { }; 7  8             Counter(1, 3, null); 9             Counter(1, 4, Conso);10             Counter(1, 4, Mess);11 12             Program p = new Program();13             Counter(1, 4, new FeedBack(p.Conso2));14 15             FeedBack f1 = new FeedBack(Conso);16             FeedBack f2 = new FeedBack(Mess);17 18             FeedBack f = null;19             f += f1;20             f += f2;21             Counter(1, 30, f);22         }23 24         private static void Counter(int from, int to, FeedBack fb)25         {26             for (int i = from; i < to; i++)27                 if (fb != null)28                     fb(i);29         }30 31         private static void Conso(int value)32         {33             Console.WriteLine("Item=" + value.ToString());34         }35 36         private void Conso2(int value)37         {38             Console.WriteLine("Item=" + value.ToString());39         }40 41         private static void Mess(int value)42         {43             MessageBox.Show("Item=" + value.ToString());44         }45 46         private void Mess2(int value)47         {48             MessageBox.Show("Item=" + value.ToString());49         }50     }

2. There are much better practices.

1             String[] names = { "Jeff", "Kristin", "Aidan", "Grant", "HaifengCai" };2             Char charToEnd = 'a';3             names = Array.FindAll(names, name => name.IndexOf(charToEnd) >= 0);4             names = Array.ConvertAll(names, name => name.ToUpper());5             Array.ForEach(names, Console.WriteLine);

 

转载于:https://www.cnblogs.com/HaifengCai/p/4084030.html

你可能感兴趣的文章
file_get_contents()获取https出现这个错误Unable to find the wrapper “https” – did
查看>>
linux vi编辑器
查看>>
js树形结构-----(BST)二叉树增删查
查看>>
contract
查看>>
Python语言编程
查看>>
[poj 1469]Courses
查看>>
vue+element-ui实现表格checkbox单选
查看>>
测试开发学习进阶教程 视频&PDF
查看>>
C#基础-连接Access与SQL Server
查看>>
autofac
查看>>
MacOS 系统终端上传文件到 linux 服务器
查看>>
Excel导出POI
查看>>
兼容性
查看>>
自动执行sftp命令的脚本
查看>>
转 Merkle Tree(默克尔树)算法解析
查看>>
网络编程基础之socket编程
查看>>
各种浏览器的user-agent和
查看>>
Restful levels
查看>>
Phonegap移动开发:布局总结(一) 全局
查看>>
Java 变参函数的实现
查看>>