ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Geometry Namespace / ReadOnlyPartCollection Class / GetEnumerator Method
Example

In This Topic
    GetEnumerator Method (ReadOnlyPartCollection)
    In This Topic
    Returns an enumerator that iterates through the collection.
    Syntax

    Return Value

    A IEnumerator that can be used to iterate through the collection.
    Example
    Enumerate the parts of a Polyline
    {
      ReadOnlyPartCollection polylineParts = polyline.Parts;
    
      // enumerate the segments to get the length
      double len = 0;
      IEnumerator<ReadOnlySegmentCollection> segmentsPolyline = polylineParts.GetEnumerator();
      while (segmentsPolyline.MoveNext())
      {
        ReadOnlySegmentCollection seg = segmentsPolyline.Current;
        foreach (Segment s in seg)
        {
          len += s.Length;
    
          // perhaps do something specific per segment type
          switch (s.SegmentType)
          {
            case SegmentType.Line:
              break;
            case SegmentType.Bezier:
              break;
            case SegmentType.EllipticArc:
              break;
          }
        }
      }
    
      // or use foreach pattern
      foreach (var part in polyline.Parts)
      {
        foreach (var segment in part)
        {
          len += segment.Length;
    
          // perhaps do something specific per segment type
          switch (segment.SegmentType)
          {
            case SegmentType.Line:
              break;
            case SegmentType.Bezier:
              break;
            case SegmentType.EllipticArc:
              break;
          }
        }
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also