Code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
public partial class SampleLinq_Sample1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
IList<Book> book = Helper.SearchBookByPrice();
foreach (Book bk in book)
{
Response.Write("书名" + bk.Title + "价钱" + bk.Price);
}
}
}
public class Book
{
/**////
/// 图书名称
///
public string Title { get; set; }
/**////
/// 单价
///
public float Price { get; set; }
/**////
/// 作者
///
public string Author { get; set; }
/**////
/// ISBN号
///
public string ISBN { get; set; }
}
public static class Helper
{
public static IList<Book> SearchBookByPrice()
{
IList<Book> books = new List<Book> {new Book{Title="InsideCOM",ISBN="123-456-789",Price=20},new Book{Title="InsideC#",ISBN="123-356-d89",Price=100},new Book{Title="Linq",ISBN="123-d56-d89",Price=120}};
IList<Book> results = new List<Book>();
foreach (Book book in books)
{
if (book.Price < 50)
{
results.Add(book);
}
}
return results;
}
}
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
public partial class SampleLinq_Sample1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
IList<Book> book = Helper.SearchBookByPrice();
foreach (Book bk in book)
{
Response.Write("书名" + bk.Title + "价钱" + bk.Price);
}
}
}
public class Book
{
/**////
/// 图书名称
///
public string Title { get; set; }
/**////
/// 单价
///
public float Price { get; set; }
/**////
/// 作者
///
public string Author { get; set; }
/**////
/// ISBN号
///
public string ISBN { get; set; }
}
public static class Helper
{
public static IList<Book> SearchBookByPrice()
{
IList<Book> books = new List<Book> {new Book{Title="InsideCOM",ISBN="123-456-789",Price=20},new Book{Title="InsideC#",ISBN="123-356-d89",Price=100},new Book{Title="Linq",ISBN="123-d56-d89",Price=120}};
IList<Book> results = new List<Book>();
foreach (Book book in books)
{
if (book.Price < 50)
{
results.Add(book);
}
}
return results;
}
}