惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - *小小黄*

JQuery常用代码1 使用Telerik控件时出现Failed to create designer 的解决方法 GridView 笔记 - *小小黄* - 博客园 Telerik Rad 笔记 一 Silverlight学习笔记四:如何通过自定义ComboBox实现SelectedValue Silverlight学习笔记三:如何自定义DataGrid的Header Silverlight学习笔记二(续) Silverlight学习笔记二:DataGrid 服务器端分页、排序的实现 Silverlight学习笔记一:DataGrid如何处理鼠标的滚轮事件 SQL2005快照 在ASP.NET中使用HTTP压缩 Web注册表单设计样式的研究(下) Web注册表单设计样式的研究(上) 禁用aspx页面的客户端缓存 DataGrid中没有数据时显示表头(转) 在 Windows Vista 上安裝 Reporting Services IIS7中访问Access数据库报错的解决方案 解决“无法删除文件:无法读源文件或磁盘” AjaxControlToolkit中的CalendarExtender被遮挡的解决方法
List<T>的Sort,Find,Exists等的使用(摘抄)
*小小黄* · 2011-03-29 · via 博客园 - *小小黄*

List<Person> lstPerson = new List<Person>();
lstPerson.Add(new Person(1, "puma", 10));
lstPerson.Add(new Person(2, "F6 Team", 20));
lstPerson.Add(new Person(3, "ASP.NET", 30));
lstPerson.Add(new Person(4, "Dotblogs", 40));

//List<T>.Find()
//找出Name='puma'的Person
lstPerson.Find(delegate(Person p) { return p.Name == "puma"; });

//List<T>.FindAll()
//找出Age>10
lstPerson.FindAll(delegate(Person p) { return p.Age > 10; });

//List<T>.Exists()
//檢查Name='F6'是否存在
lstPerson.Exists(delegate(Person p) { return p.Name == "F6"; });

//List<T>.Sort()
//依Name升序排序
lstPerson.Sort(delegate(Person p1, Person p2) { return Comparer<string>.Default.Compare(p1.Name, p2.Name); });

//List<T>.Sort()
//依Name降序排序
lstPerson.Sort(delegate(Person p1, Person p2) { return Comparer<string>.Default.Compare(p2.Name, p1.Name); });

有一个list,格式如list<userType>, 但是这个userType并没有继承自ICompare或者IComparable 等,那如何给这个list排序那?
指定一个类 这个类要继承自ICompare<userType>
public class SortUserGroup:IComparer<UserGroup>
{
    /// <summary>
    /// Sort by AccountID and UserGroupName
    /// </summary>
    /// <param name="userGroup1"></param>
    /// <param name="userGroup2"></param>
    /// <returns></returns>
    int IComparer<UserGroupEntityAccess>.Compare(UserGroup userGroup1, UserGroup userGroup2)
    {
        if (userGroup1 != null && userGroup2 != null)
        {
        if (userGroup1.AccountID == userGroup2.AccountID)
            return userGroup1.UserGroupName.CompareTo(userGroup2.UserGroupName);
        else
            return userGroup1.AccountID > userGroup2.AccountID ? 1 : -1;
        }
        return -1;
    }
}
然后:
SortUserGroup sortGroup = new SortUserGroup();
List<UserGroup>.Sort(sortUserGroup)
这里是按照UserGroup的AccountID 和 UserGroupName 两个字段排序。

详细的Sort用法

c#范型List的Sort方法详解