webform1.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test13_2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<News> dataM = new List<News>
{
new News { title="冬奥会开幕了!",id=4888,categories="国际新闻"},
new News { title="中国第一艘航母下水!",id=4580,categories="中国新闻"},
new News { title="IPHONE 5S上市了!",id=4688,categories="国际新闻"},
new News { title="发行新股将实行注册制度!",id=3888,categories="中国新闻"},
new News { title="美国政府暂时停止工作!",id=2888,categories="国际新闻"},
new News { title="新兴市场股票大涨!",id=4568,categories="国际新闻"}
};
var query1 = from str in dataM
where str.categories == "国际新闻"
orderby str.id descending
select str.title; // select str;
Response.Write("<strong>热点新闻包括:</strong><br>");
foreach (var news in query1)
{
Response.Write(news + "<br>");
//Response.Write(news.title + "<br>");
}
}
}
}
news.cs class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test13_2
{
class News
{
public int id { get; set; }
public string title { get; set; }
public string categories { get; set; }
}
}