zoukankan      html  css  js  c++  java
  • C#

    有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

    如果需要多个字段排序:

    http://stackoverflow.com/questions/3047455/linq-orderby-with-more-than-one-field

  • 相关阅读:
    学习进度02
    dataX windows10安装
    架构漫谈 阅读笔记03
    质量属性及战术
    架构漫谈 阅读笔记02
    2020.12.12收获
    2020.12.11收获
    2020.12.10收获
    2020.12.9收获
    2020.12.8收获
  • 原文地址:https://www.cnblogs.com/mantian/p/3740358.html
Copyright © 2011-2022 走看看