C# Sortable collection which allows duplicate keys

前端 未结 16 2142
旧巷少年郎
旧巷少年郎 2020-11-28 10:06

I am writing a program to set a sequence in which various objects will appear in report. The sequence is the Y position (cell) on Excel spreadsheet.

A demo part of co

16条回答
  •  借酒劲吻你
    2020-11-28 10:58

    You can safely use List<> . The List has a Sort method , an overload of which accepts IComparer. You can create your own sorter class as . Here's an example :

    private List Curves;
    this.Curves.Sort(new CurveSorter());
    
    public class CurveSorter : IComparer
    {
        public int Compare(Curve c1, Curve c2)
        {
            return c2.CreationTime.CompareTo(c1.CreationTime);
        }
    }
    

提交回复
热议问题