问题:ArgumentException: 'Unable to sort because the IComparer. Compare() method returns inconsistent results. Either a value does not compare equal to itself, or one value repeatedly compared to another value yields different results.
定位问题,如何通过测试代码,复现此报错:
CompareTo的值,如果在计算过程中发生了异常报错,则会出现此报错信息。因为比较值得不到,无法进行比较进行返回。
解决办法:
1.代码写健壮,判空处理。使整个流程不出异常。
2.一定有返回值。0,-1,1。