List.Sort in C#: comparer being called with null object

后端 未结 7 1158
攒了一身酷
攒了一身酷 2021-01-01 11:48

I am getting strange behaviour using the built-in C# List.Sort function with a custom comparer.

For some reason it sometimes calls the comparer class\'s Compare meth

相关标签:
7条回答
  • 2021-01-01 12:40

    Can you run this code ...

    mylst.Sort((i, j) =>
                  {
                      Debug.Assert(i.SomeProp != null && j.SomeProp != null);
                      return i.SomeProp.CompareTo(j.SomeProp);
                  }
             );
    
    0 讨论(0)
提交回复
热议问题