ArcGIS Pro 3.7 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 Overloads Function ToDictionary(Of T As MapMember)() As Dictionary(Of T,List(Of Long))
    public Dictionary<T,List<long>> ToDictionary<T>()
    where T: MapMember

    Type Parameters

    T

    Return Value

    Dictionary of mapMembers and their corresponding objectIDs.
    Example
    Load map selection into Inspector
    {
      // Loads the selected features into an Inspector instance.
      // get the first layer and its corresponding selected feature OIDs
      var firstSelectionSet = selectedFeatures.ToDictionary().First();
      // create an instance of the inspector class
      var inspector = new Inspector();
      // load the selected features into the inspector using a list of object IDs
      await inspector.LoadAsync(firstSelectionSet.Key, firstSelectionSet.Value);
    }
    Get selected feature's attribute value
    // Retrieves the value of a specific attribute and the geometry of the first selected feature from the provided selection set.
    await QueuedTask.Run(() =>
    {
      // get the first layer and its corresponding selected feature OIDs
      var firstSelectionSet = selectedFeatures.ToDictionary().First();
    
      // create an instance of the inspector class
      var inspector = new Inspector();
    
      // load the selected features into the inspector using a list of object IDs
      inspector.Load(firstSelectionSet.Key, firstSelectionSet.Value);
    
      //get the value of
      var pscode = inspector["STATE_NAME"];
      var myGeometry = inspector.Shape;
    });
    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>();
    }
    Get OIDS from a SelectionSet for a given MapMember by Name
    {
        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 kvp = selSet.ToDictionary().Where(kvp => kvp.Key.Name == "LayerName").FirstOrDefault();
        var oidList = kvp.Value;
    }
    Requirements

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

    ArcGIS Pro version: 3.4 or higher.
    See Also