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

namespace lambda
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("传统的委托代码示例:");
FindListDelegate();
Console.WriteLine("\n");
Console.WriteLine("使用匿名方法的示例:");
FindListAnonymousMethod();
Console.WriteLine("\n");
Console.WriteLine("使用Lambda的示例: ");
FindListLambdaExpression();
}
//传统调用委托的示例
private static void FindListDelegate()
{
List<string> list=new List<string>();
list.AddRange(new string[]{"ASP.NET课程","J2EE课程","PHP课程","数据结构课程"});
Predicate<string> finPredicate=new Predicate<string>(IsBookCategory);
List<string> BookCategory = list.FindAll(finPredicate);
foreach (string str in BookCategory)
{
Console.WriteLine("{0}\t",str);
}
}

private static bool IsBookCategory(string str)
{
return str.EndsWith("课程")?true:false;
}

private static void FindListAnonymousMethod()
{
List<string> list = new List<string>();
list.AddRange(new string[] { "ASP.NET课程", "J2EE课程", "PHP课程", "数据结构课程" });
List<string> bookCategory = list.FindAll(delegate(string str)
{
return str.EndsWith("课程")?true:false;
});
foreach (string str in bookCategory)
{
Console.WriteLine("{0}\t",str);
}
}

private static void FindListLambdaExpression()
{
List<string> list = new List<string>();
list.AddRange(new string[] { "ASP.NET课程", "J2EE课程", "PHP课程", "数据结构课程" });
List<string> bookCategory=list.FindAll((string str)=>str.EndsWith("课程"));
foreach (string str in bookCategory)
{
Console.WriteLine("{0}\t",str);
}
Console.ReadLine();

}
}
}

最新文章

  1. 虚拟化平台cloudstack(2)——安装(上)
  2. JS,Jquery获取各种屏幕的宽度和高度
  3. freeCodeCamp:Find the Longest Word in a String
  4. 【转】vs2012 打包安装更改 setup.exe的图标
  5. js的in运算符与instanceof运算符
  6. iOS与HTML5交互方法总结(转)
  7. VC判断当前用户有无Administrator的权限(用EqualSid API函数判断与Admin是否在一个组的Sid)
  8. Away3D带你360&#176;漫游全景影像
  9. Laravel项目修改时区
  10. [js高手之路] es6系列教程 - 箭头函数详解
  11. Python中列表、元组、字典增删改查基本区别
  12. Javascript高级编程学习笔记(28)—— BOM(2)window对象2
  13. extern介绍
  14. 序列操作bzoj2962(未完成)
  15. 看图写代码---看图写代码 阅读&lt;&lt;Audio/Video Connectivity Solutions for Virtex-II Pro and Virtex-4 FPGAs &gt;&gt;
  16. 更好的转换规则(深入理解c#)
  17. 使用Font Awesome替换你的网站图标(icons 图标)
  18. socat 的神奇使用方式
  19. day5模块学习--shelve模块
  20. java截取字符串

热门文章

  1. C语言字符串比较(转)
  2. Codeforces Gym 100203I I - I WIN 网络流最大流
  3. MATLAB学习笔记(三)&mdash;&mdash;程序设计
  4. C#学习笔记(六)——面向对象编程简介
  5. 利用jquery给指定的table动态添加一行、删除一行
  6. ie9始终提示文档预览需要最新版本的Flash Player支持的解决方法:
  7. JVM的类加载机制
  8. JVM的粗略简述
  9. Sky数[HDU2097]
  10. lua ipairs