The problem with the list, is that the point is “copied out of the list” and into your variable. It’s not obvious or intuitive that it is so, and therefore this error tends to creep in.
But in the case of the array you actually transform the “original in it place in the array” (not copied out of the array). The problem has to do with
structs (so for example a List of vectors, and other structs, would have the same problem).
Classes generally don’t have this problem, which is why other object types works well (so this doesn’t have primarily with lists or foreach to do, it has to do with structs ).
Last time when I had the need to hold my points (Point3d) in a list - while also having to perform transforms on them - I used the type Point instead (List< Point >). Then you can operate directly on the list items (like in the case of the array) since a Point class can be referenced, whereas structs can’t.
So, what I am saying is that your code would actually work if you first convert your List< Point3d > to a List< Point > and traverse that list instead, like so:
var pointList = new List<Point>();
foreach (var pt in xPts)
pointList.Add( new Point(pt) );
Now your old code would work, if replacing the
xPts with the
pointList (just like I replaced it with an array).
foreach (var pt in pointList)
A = pointList; // or whatever outport name you use
The benefit with Point is that they are of the same “kind” (has a common super class) as other Geometry types, being a class, and they inherit from the GeometryBase class, see this link for Point ).