LINQPad 如何使用自定义程序集的类 进行查询测试?
想在LINQPad 进行如下测试:(其中Book为自定义类)
List<Book> books = new List<Book>() {
new Book { Title="LINQ in Action" },
new Book { Title="LINQ for Fun" },
new Book { Title="Extreme LINQ" } };
var titles =
books
.Where(book => book.Title.Contains("Action"))
.Select(book => book.Title);
titles.Dump();
自定义一个类:
public class Book
{
public string Title { get; set; }
}
我使用右击LINQPad编辑器,引用Book所在的程序集,在LINQPad 执行还是报一些语法错误,请大家找下什么问题?
------解决方案--------------------
Language 选择 C# Program
然后将下边代码复制粘贴进LINQPAD:
C# code
void Main()
{
List<Book> books = new List<Book>() {
new Book { Title="LINQ in Action" },
new Book { Title="LINQ for Fun" },
new Book { Title="Extreme LINQ" } };
var titles =
books
.Where(book => book.Title.Contains("Action"))
.Select(book => book.Title);
Console.WriteLine(titles);
}
public class Book
{
public string Title { get; set; }
}
// Define other methods and classes here
------解决方案--------------------
http://www.linqpad.net/