At least one object must implement IComparable

后端 未结 5 375
攒了一身酷
攒了一身酷 2020-12-06 08:48
using System;
using System.Xml;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
             


        
5条回答
  •  自闭症患者
    2020-12-06 09:47

    This is a more general answer to this error i suppose.

    This line will fail with the error you got:

    Items.OrderByDescending(t => t.PointXYZ);
    

    However you can specify how to compare it directly:

    Items.OrderByDescending(t => t.PointXYZ.DistanceTo(SomeOtherPoint))
    

    Then you dont need the IComparable interface. Depends on the API you are using. In my case i have a Point and a DistanceTo-method. (Revit API) But an integer should be even easier to determine the "size/position" of.

提交回复
热议问题