Is there a list that is sorted automatically in .NET?

前端 未结 8 1183
轻奢々
轻奢々 2021-02-05 04:00

I have a collection of Layers where they have names and colors. What I want to do is to sort these first based on colors, then based on their names:



        
8条回答
  •  一向
    一向 (楼主)
    2021-02-05 04:30

    You could use the regular List, but call the Sort() method prior to displaying the list, and after new values are added. That should give you the functionality that you need. The performance will be good enough for this application.

    Of course, you will have to define your own comparison for it to use, but that shouldn't be too much trouble.

    If you don't have any hooks into the add event that can be used to sort the list, then you can wrap the list in a custom collection class as @Justin recommends.

提交回复
热议问题