ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapMemberIDSet Class / ToDictionary Method / ToDictionary<T>() Method
Example

In This Topic
    ToDictionary<T>() Method
    In This Topic
    Creates the dictionary of mapMembers and their corresponding objectIDs.
    Syntax
    public Dictionary<T,List<long>> ToDictionary<T>()
    where T: MapMember
    Public Overloads Function ToDictionary(Of T As MapMember)() As Dictionary(Of T,List(Of Long))

    Type Parameters

    T

    Return Value

    Dictionary of mapMembers and their corresponding objectIDs.
    Example
    Translate from SelectionSet to Dictionary
    {
      MapMember us_zips_layer = map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First(s => s.Name == "USA zips layer");
    
      var addToSelection = new Dictionary<MapMember, List<long>>();
      addToSelection.Add(us_zips_layer, new List<long> { 1506, 2696, 2246, 1647, 948 });
      //Create a SelectionSet object
      var selSet = ArcGIS.Desktop.Mapping.SelectionSet.FromDictionary(addToSelection);
      var selSetDict = selSet.ToDictionary();
    
      // convert to the dictionary and only include those that are of type FeatureLayer
      var selSetDictFeatureLayer = selSet.ToDictionary<FeatureLayer>();
    }
    Select features via the MapView
    {
      //assume the geometry used in SelectFeaturesEx() is coming from a
      //map tool...
      //SketchType = SketchGeometryType.Rectangle;
      //SketchOutputMode = SketchOutputMode.Screen;
    
      var mapView = MapView.Active;
      if (mapView == null)
        return;
    
      await QueuedTask.Run(() =>
      {
        var result = mapView.SelectFeaturesEx(geometry);
        //Get scene layers with selections
        var scene_layers = result.ToDictionary<FeatureSceneLayer>();
        foreach (var kvp in scene_layers)
        {
          var scene_layer = kvp.Key as FeatureSceneLayer;
          var sel_oids = kvp.Value;
          //If there are attributes then get them
          if (scene_layer.HasAssociatedFeatureService)
          {
            var insp = new Inspector();
            foreach (var objectid in sel_oids)
            {
              insp.Load(scene_layer, objectid);
              //TODO something with retrieved attributes
            }
          }
        }
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.4 or higher.
    See Also