合并多个List类型并通过LINQ按指定属性排序

后台CS代码:

namespace WebFormTest.TestCollect
{
public partial class ListTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<Person> list1 = new List<Person>();
list1.Add(new Person() { Age = , Name = "张三", Time = Convert.ToDateTime("2013/12/20 13:20") });
list1.Add(new Person() { Age = , Name = "李四", Time = Convert.ToDateTime("2013/12/20 14:20") });
list1.Add(new Person() { Age = , Name = "王五", Time = Convert.ToDateTime("2013/12/20 13:40") }); List<Person> list2 = new List<Person>();
list2.Add(new Person() { Age = , Name = "张三2", Time = Convert.ToDateTime("2013/12/20 13:20") });
list2.Add(new Person() { Age = , Name = "李四2", Time = Convert.ToDateTime("2013/12/20 14:20") });
list2.Add(new Person() { Age = , Name = "王五2", Time = Convert.ToDateTime("2013/12/20 13:40") }); list1 = list1.Concat(list2).ToList(); //合并多个list<T> list1 = list1.OrderByDescending(i => i.Time).ToList(); //降序排列
//list.OrderBy(i => i.Time);升序排列 Repeater1.DataSource = list1;
Repeater1.DataBind();
}
} public class Person
{
private int age; public int Age
{
get { return age; }
set { age = value; }
}
private string name; public string Name
{
get { return name; }
set { name = value; }
} private DateTime time; public DateTime Time
{
get { return time; }
set { time = value; }
} }
}

前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListTest.aspx.cs" Inherits="WebFormTest.TestCollect.ListTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td>
<%#Eval("Age") %>
</td>
<td>
<%#Eval("Name") %>
</td>
<td>
<%#Eval("Time") %>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
</form>
</body>
</html>

效果展示:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAp8AAACUCAIAAABa0tW1AAAOAUlEQVR4nO3dW5qbOhCFUQ8u880QfR46cTgI7SpdMKrSvx7ydYNVluyWNuBLXm8AAJDL6+kOAACAyUh3AACyId0BAMiGdAcAIBvSHQCAbKrp/hsAAMSk0v1XFpnGAjyCSQTEYqT76KWBNeixvF68PAEYMi0IwA5Id9IdsGVaEIAdbJfuL59j844mQDKLLAjTJxozF1ltl+4nnmw+7vX8DOSzwoKQMtpX6ANSstM9wUlqbWH6Gcvx30ukO1C7AFbeUi8Uuon/OPuOgiPj8t9L095aHyb28I4hYwWudP9if25xme6fcZU/1G7p/BnIp7YgiF9r2XmqrAuemt9XsHtcgpmOTdl5Uw/nFsQ6dkx3MavNxYJ0x5486W4GrWeL5yD7joKD4xJ0B6ake18PRavBIWMFe6W750i/vBnpDtyX7s69ydJd5Ojbt1I19dC/9DkLYn3edDcvMa2sdmW+dNm89hdPumMf+uWty1+dWz7bO6Jd79J352+1SLqP9JB035Ar3aPHmOftvp7lo3aWH/e4B3C6O9313mTpPr6iTukh6Z6bne7nBgGfYzPdPVO9bxEBcignUV+WmzNl1gGB2NVacLV0n9VD0j23vdL98mp8zae559Q84sMC+JVvTS1vs1S6953ud49LqNXsu/I3sYeke27e193/NQj4HA9+E23fPAEyOX3e/fI2U87my1870l3nd+sBwR3pPrcU6Y4S6e5K96ZzfSCf8c+71zb6C16aVXBwXE09NPdeLikjPaytUaLVyJCxAteV+egZ5vmuOoFzd8D/5ZXm9nKvrlbrUq2g7qFI975xCc6CtQdkYg9Fz81WTUPGOppfd49If8/8lzsDRPTIgjB9ejLfsY/d0x2AB5MIiIV0B2BjEgGxkO4AbEwiIBaV7gAAICLj3D2HTGMBHsEkAmLhyjxvowVsmRYEYAekO+kO2DItCMAOtkv38hshLh2bdzQBkllkQeAT8IDTdul+4snm1/+/Bsv8GchnhQUhZbSv0Aek5Pqe+egnqbWF6XX4J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47uTne9N2W6d5SqterrIeme23bp/vGFdI/7iAEnngVhPN07mky5mN/agYnp3lrN2R/SHaS78fJVt7gPF1A6TaLaq8UdWwabzD3d7x6XMDfdJ/aQdM+NdPe+B6dJ3McKuKTfvFLb3rHF84KxLih6qAuOjEtoHXJTKeddtLYi3RMg3f/8UDuDf7Uom5e/AhGNf969ttFf8NKsgoPjmtjDd+UQZKSHtWMa0WpkyFiBK90vMyyQ8rSjzO9Tk5Fh1lIfiKv2XzHVgkRsL/fqarUu1QrqHtYKdo9L6Bvyu74odfdQ9Nxs1TRkrKPh3D0u/ZIhf7uA6ZEFYfrcZLJjHzumO4BWTCIgFtIdgI1JBMRCugOwMYmAWFS6AwCAiKrp/gsAAMTEO0gBAMiGdAcAIBvSHQCAbEh3AACyId0BAMiGdAcAIBvSHQCAbEh3AACyId0BAMiGdAcAIBvSHQCAbEh3AACyId0BAMiGdAcAIJv/AKsOYih57xeJAAAAAElFTkSuQmCC" alt="" />

上一篇:51nod算法马拉松13


下一篇:免费网站监控服务阿里云监控,DNSPod监控,监控宝,360云监控使用对比