【问题标题】:Sorting a LinkedList by string name alphabetically in C#在 C# 中按字符串名称的字母顺序对 LinkedList 进行排序
【发布时间】:2020-05-20 21:51:48
【问题描述】:

谁能解释我如何按对象名称的字母顺序对链接列表进行排序。

 //so lets say i have an Animal:
        public Animal()
        {
            name = null;
            age = 0;
            mass = 0;
        }

并想在 main() 中创建此动物的随机对象,并将它们随机插入到链表中。 然后我如何按名称属性按字母顺序对这个动物链接列表进行排序:(

【问题讨论】:

标签: c# string sorting linked-list


【解决方案1】:

假设您使用 List 作为链表,这应该可以工作。

animals = animals.OrderBy(animal => animal.name).ToList();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    相关资源
    最近更新 更多