ArcGIS Pro 2.9 API Reference Guide
CreateGeometryBag(IEnumerable<Geometry>,SpatialReference) Method
Example 

ArcGIS.Core.Geometry Namespace > GeometryBagBuilder Class > CreateGeometryBag Method : CreateGeometryBag(IEnumerable<Geometry>,SpatialReference) Method
The list of geometries to create the GeometryBag.
(Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference of the geometries in the GeometryBag will also be null. This could lead to unexpected behavior if a geometry in the list has a non-null spatial reference. If spatialReference is not null and a geometry in the list of geometries has a different spatial reference, the geometry will be projected to spatialReference before it is inserted into the GeometryBag.
Convenience method to create a new instance of the GeometryBag class.
Syntax
Public Overloads Shared Function CreateGeometryBag( _
   ByVal geometries As IEnumerable(Of Geometry), _
   Optional ByVal spatialReference As SpatialReference _
) As GeometryBag

Parameters

geometries
The list of geometries to create the GeometryBag.
spatialReference
(Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference of the geometries in the GeometryBag will also be null. This could lead to unexpected behavior if a geometry in the list has a non-null spatial reference. If spatialReference is not null and a geometry in the list of geometries has a different spatial reference, the geometry will be projected to spatialReference before it is inserted into the GeometryBag.

Return Value

Exceptions
ExceptionDescription
geometries is null.
A geometry in geometries is null. You cannot insert a null geometry into GeometryBag.
A geometry in geometries is a GeometryBag. A GeometryBag cannot contain another GeometryBag.
Remarks
An Envelope is converted to a Polygon when it is inserted into a GeometryBag. As a result, when retrieving an Envelope from a GeometryBag, it will be a Polygon.
Example
// Use a builder convenience method or use a builder constructor.

MapPoint point = MapPointBuilder.CreateMapPoint(10, 20);
List<Coordinate2D> coords = new List<Coordinate2D>() { new Coordinate2D(50, 60), new Coordinate2D(-120, -70), new Coordinate2D(40, 60) };
Multipoint multipoint = MultipointBuilder.CreateMultipoint(coords, SpatialReferences.WebMercator);
Polyline polyline = PolylineBuilder.CreatePolyline(coords);

string json = "{\"rings\":[[[0,0],[0,1],[1,1],[1,0],[0,0]],[[3,0],[3,1],[4,1],[4,0],[3,0]]]}";
Polygon polygon = PolygonBuilder.FromJson(json);

var geometries = new List<Geometry>() { point, multipoint, polyline, polygon };

// Builder convenience methods don't need to run on the MCT.
GeometryBag bag = GeometryBagBuilder.CreateGeometryBag(geometries, SpatialReferences.WGS84);

// Builder constructors need to run on the MCT.
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
  using (var builder = new GeometryBagBuilder(geometries, SpatialReferences.WGS84))
  {
    // builder.CountGeometries = 4

    // do something with the builder

    bag = builder.ToGeometry();
    // bag.PartCount = 4
    // bag.PointCount = 17
  }
});
Requirements

Target Platforms: Windows 11, Windows 10, Windows 8.1

See Also

Reference

GeometryBagBuilder Class
GeometryBagBuilder Members
Overload List