How to get the geometry from an ILayer object in C#

Discussion created by reneecammarere on Mar 3, 2011
Latest reply on Mar 7, 2011 by geoelement
From reading the documentation, I assumed that this was the way to accomplish that.  However, I got an error when I tried to cast an ILayer object to an IFeatureLayer object.  This is the snippit of code:

ILayer pLayer = aMap.get_Layer(layercount - 1);
IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
IFeature pFeature = pFeatureClass.CreateFeature();
IGeometry pGeometry = pFeature.Shape;