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

前端 未结 8 1203
轻奢々
轻奢々 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:26

    Start by implementing the IComparable interface in Layer and declaring a CompareTo method. Then use a SortedList collection to store your object.

     public class Layer : IComparable {
    
        public int CompareTo(object obj) {
              //return -1 if this is before obj, 0 is same, 1 is after.
        }
    
     }
    

提交回复
热议问题