ArcGIS Pro 2.8 API Reference Guide
CreatePolyline(IEnumerable<MapPoint>,SpatialReference) Method
Example 

ArcGIS.Core.Geometry Namespace > PolylineBuilder Class > CreatePolyline Method : CreatePolyline(IEnumerable<MapPoint>,SpatialReference) Method
Coordinates to create the polyline.
(Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference will be inherited from points.
Convenience method to create a new instance of the Polyline class.
Syntax
Public Overloads Shared Function CreatePolyline( _
   ByVal points As IEnumerable(Of MapPoint), _
   Optional ByVal spatialReference As SpatialReference _
) As Polyline

Parameters

points
Coordinates to create the polyline.
spatialReference
(Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference will be inherited from points.

Return Value

Exceptions
ExceptionDescription
Incompatible spatial references.
points is null.
Example
// Use a builder convenience method or use a builder constructor.

MapPoint startPt = MapPointBuilder.CreateMapPoint(1.0, 1.0);
MapPoint endPt = MapPointBuilder.CreateMapPoint(2.0, 1.0);

List<MapPoint> list = new List<MapPoint>();
list.Add(startPt);
list.Add(endPt);

// Builder convenience methods don't need to run on the MCT.
Polyline polyline = PolylineBuilder.CreatePolyline(list, SpatialReferences.WGS84);

// Builder constructors need to run on the MCT.
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
  using (PolylineBuilder pb = new PolylineBuilder(list))
  {
    pb.SpatialReference = SpatialReferences.WGS84;
    Polyline polyline2 = pb.ToGeometry();
  }
});


// buildEx constructors don't need to run on the MCT
PolylineBuilderEx pBuilder = new PolylineBuilderEx(list);
pBuilder.SpatialReference = SpatialReferences.WGS84;
Polyline polyline3 = pBuilder.ToGeometry() as Polyline;


// builderEx convenience methods don't need to run on the MCT
//     use AttributeFlags.NoAttributes because we only have 2d points in the list
Polyline polyline4 = PolylineBuilderEx.CreatePolyline(list, AttributeFlags.NoAttributes);
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

PolylineBuilder Class
PolylineBuilder Members
Overload List