怎么改?
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LambdaDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("传统的委托代码示例:");
FindListDelegate();
Console.WriteLine("\n");
Console.WriteLine("使用匿名方法的示例:");
FindListAnonymousMethod();
Console.WriteLine("\n");
Console.WriteLine("使用Lambda的示例:");
FindListLambdaExpression();
}
static void FindListDelegate()
{
List<string> list = new List<string>();
list.AddRange(new string[] { "课程", "J2EE课程", "PHP课程", "数据结构课程" });
Predicate<string>findPredicate=new Predicate<string>(IsBookCategory);
List<string>bookCategory=list.FindAll(findPredicate);
foreach(string str in bookCategory)
{
Console.WriteLine("{0}\t",str);
}
}
static void FindListAnonymousMethod()
{
List<string>list=new List<string>();
list.AddRange(new string[]{"课程","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);
}
}
static void FindListLambdaExpression()
{
List<string> list = new List<string>();
list.AddRange(new string[] { "课程", "J2EE课程", "PHP课程", "数据结构课程" });
List<string> bookGategory = list.FindAll((string str)=>str.EndsWith("课程"));
foreach (string str in bookGategory)
{
Console.WriteLine("{0}\t", str);
}
}
}
}
提示错误错误 1 当前上下文中不存在名称“IsBookCategory” 动态网站开发基础教程书中第51页的源代码;请高手指点,如何修改,为什么