日期:2014-05-17 浏览次数:20504 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ForWangYongB{
class Program{
static void Main(string[] args){
var entities = new Entity[8];
entities[0] = new Entity("标题1","国内新闻", 1);
entities[1] = new Entity("标题2", "国内新闻", 2);
entities[2] = new Entity("标题3", "国内新闻", 3);
entities[3] = new Entity("标题1", "国际新闻", 4);
entities[4] = new Entity("标题2", "国际新闻", 5);
entities[5] = new Entity("标题3", "国际新闻", 6);
entities[6] = new Entity("标题1", "火星新闻", 7);
entities[7] = new Entity("标题2", "火星新闻", 8);
var max = entities.GroupBy(x => x.Class)//按频道分类
.SelectMany(x => x.OrderByDescending(y=>y.Id).Take(2))//1)每个频道的文章倒序取前2条,2)实际改为Take(10)即可
//.OrderBy(x=>x.Class)如果需要类别排序
//.ThenBy(x=>x.Id) 如果需要ID排序
.ToArray();
foreach (var item in max){