有Family的类如下:
public class FamilyModel { public string Name { set; get; } }
创建List
List<FamilyModel> listFamily = new List<FamilyModel>(); listFamily.Add(new FamilyModel { Name="bbb"}); listFamily.Add(new FamilyModel { Name = "abc" }); listFamily.Add(new FamilyModel { Name = "fgd" });
想要按Name把这个List<FamilyModel>排序:
// 直接更改当前List listFamily.Sort((x, y) => string.Compare(x.Name, y.Name)); // 生成新的List var newList = listFamily.OrderBy(x => x.Name).ToList(); // ToList optional
方法来自:http://stackoverflow.com/questions/188141/c-sharp-list-orderby-alphabetical-order
C# - List操作 - 按照字母排序,布布扣,bubuko.com
原文:http://www.cnblogs.com/mantian/p/3740358.html