Implicitly convert problem

I defined a method, but the following error occurred. Anyone have a solution for this?
Cannot implicitly convert “System.Collections.Generic.IEnumerable<Rhino.Geometry.Line>type" to “System.Collections.Generic.List<Rhino.Geometry.Line>”. There is an explicit conversion (is there a missing cast?)

  List<Line> ptRelatedLine(Point3d pt, List<Line> lines)
    var localLines = lines.Where(item  => (item.To).X > pt.X);
    return localLines;


You are trying to downcast which is disallowed implicitly.

Thank you very much, but I want to know why they need to be converted. Aren’t they all of the same type (List)?

List<T> implements IEnumerable<T> so you were casting a ‘larger’ object to a ‘smaller’ object (downcasting). Enumerable.Where is an extension method from System.Linq, not from List<T> so its return is not a list.

List<T> 实现了 IEnumerable<T> 接口,所以 IEnumerable<T> 是个更大的概念,可以直接把更小的变成更大的(upcasting),但是你的代码是把更大的变成更小(downcasting),这是不行的

Enumerable.WhereSystem.Linq 提供的扩展方法,不是 List<T> 自身的,所以返回值不是 List<T>