Help with copy code from python to c#

Hi all,

i have no idea why the c# result is different to python.
No error and in my view exactly the same thing but obvious not because of different results.
Python works and c# does not.

Python

import Rhino as rh

C = [] # Sorted rig


# Order to calculate 
def calculation_order(x):
    if len(x) >= 0:
        for j in x:
            L = []
            for e in x:
                if e != j:
                    CrvEnd = rh.Geometry.CurveEnd.Both
                    ej = rh.Geometry.Curve.Trim(j,CrvEnd,2)
                    
                    L.append(rh.Geometry.Curve.ClosestPoint(ej,e.PointAtStart,0.01)[0])
                    L.append(rh.Geometry.Curve.ClosestPoint(ej,e.PointAtEnd,0.01)[0])
                    
                    
            if any(L) == False:
                C.append(j)
                x.remove(j)
                return calculation_order(x)
calculation_order(x)

and c#


 private void RunScript(List<Curve> x, ref object B)
  {
    List <Curve> A = calculation_order(x);
    B = A;
  }

  // <Custom additional code> 

  List <Curve> C = new List <Curve> ();
  List <Curve> calculation_order(List <Curve> x)
  {
    if (x.Count >= 0)
    {
      foreach (Curve j in x)
      {
        List<object> L = new List<object>();
        foreach (Curve e in x)
        {
          if (e != j)
          {
            var CrvEnd = Rhino.Geometry.CurveEnd.Both;
            Curve ej = j.Trim(CrvEnd, 2);
            Point3d StartPoint = e.PointAtStart;
            Point3d EndPoint = e.PointAtEnd;
            double t;

            bool SpClosestPt = ej.ClosestPoint(StartPoint, out t, 0.01);
            bool EpClosestPt = ej.ClosestPoint(EndPoint, out t, 0.01);

            L.Add(SpClosestPt);
            L.Add(EpClosestPt);
          }
        }
        if (L.Contains(false))
        {
          C.Add(j);
          x.Remove(j);
          return calculation_order(x);
        }
      }
    }
    return C;
  }
  // </Custom additional code> 
}

I really hope someone see my fault.

I haven’t managed to make your python code work…
Can you attach them both inside scripts in a .gh file?

Many thanks that you took a look into it.
Here is the Rhino and grasshopper file

rig_weight_point.3dm (56.3 KB) test.gh (9.5 KB)

The first two nodes after the Geo node are the one with the posted code.
The curve order from the python list is the wanted one.

after analysing every single line of the code i got different outputs after the following line.

In Python

if any(L) == False:

in C#

if (L.Contains(false))
//This statement isn´t the same as in the python line
//it says if the list L contains false but not that all L items are false
//so the right description with contains in c# to any in python is if no item is true
//so this is the equivalent statement
if (!L.Contains(true))

So thanks for interest and looking into it.