ArcGIS Pro 2.7 API Reference Guide
Within Method (IGeometryEngine)
Example 

ArcGIS.Core.Geometry Namespace > IGeometryEngine Interface : Within Method
The base geometry.
The comparison geometry.
Returns true if geometry1 is within geometry2.
Syntax

Parameters

geometry1
The base geometry.
geometry2
The comparison geometry.

Return Value

True if geometry1 is within geometry2.
Exceptions
ExceptionDescription
Either geometry1 or geometry2 or both are null or empty.
The method is not implemented for GeometryBag.
Incompatible spatial references between the input geometries.
Remarks
If both geometry1 and geometry2 are not empty, then geometry1 is within geometry2 if the intersection of their interiors is not empty and geometry1 is a subset of geometry2.

If the geometry2 is empty, then geometry1 is not within geometry2.

If geometry1 is empty and geometry2 is not empty, then geometry1 is within geometry2.

Within is the opposite of Contains. That is, geometry1 is within geometry2 if and only if geometry2 contains geometry1.

GeometryEngine Within

Example
// build a polygon      
List<MapPoint> pts = new List<MapPoint>();
pts.Add(MapPointBuilder.CreateMapPoint(1.0, 1.0));
pts.Add(MapPointBuilder.CreateMapPoint(1.0, 2.0));
pts.Add(MapPointBuilder.CreateMapPoint(2.0, 2.0));
pts.Add(MapPointBuilder.CreateMapPoint(2.0, 1.0));

Polygon poly = PolygonBuilder.CreatePolygon(pts);

// an inner point
MapPoint innerPt = MapPointBuilder.CreateMapPoint(1.5, 1.5);
bool within = GeometryEngine.Instance.Within(innerPt, poly);   // within = true

// point on a boundary
within = GeometryEngine.Instance.Within(pts[0], poly);     // within = false

// an interior line
MapPoint innerPt2 = MapPointBuilder.CreateMapPoint(1.25, 1.75);
List<MapPoint> innerLinePts = new List<MapPoint>();
innerLinePts.Add(innerPt);
innerLinePts.Add(innerPt2);

Polyline polyline = PolylineBuilder.CreatePolyline(innerLinePts);
within = GeometryEngine.Instance.Within(polyline, poly);   // within = true

// a line that crosses the boundary
MapPoint outerPt = MapPointBuilder.CreateMapPoint(3, 1.5);
List<MapPoint> crossingLinePts = new List<MapPoint>();
crossingLinePts.Add(innerPt);
crossingLinePts.Add(outerPt);

polyline = PolylineBuilder.CreatePolyline(crossingLinePts);
within = GeometryEngine.Instance.Within(polyline, poly);     // within = false


// polygon in polygon
Envelope env = EnvelopeBuilder.CreateEnvelope(innerPt, innerPt2);
within = GeometryEngine.Instance.Within(env, poly);      // within = true
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

IGeometryEngine Interface
IGeometryEngine Members