How is the c#/.net 3.5 dictionary implemented?

后端 未结 5 1281
無奈伤痛
無奈伤痛 2020-12-01 00:22

I\'m using an application which uses a number of large dictionaries ( up to 10^6 elements), the size of which is unknown in advance, (though I can guess in some cases). I\'m

5条回答
  •  猫巷女王i
    2020-12-01 00:40

    • JSON as dictionary
    {
     "Details": 
        { 
        "ApiKey": 50125
        }
    }
    
    • Model should contain property as type Dictionary.
    public Dictionary Details{ get; set; }
    
    • Implement foreach() block with datatype as "KeyValue"
           foreach (KeyValuePair dict in Details)
                    {
                        switch (dict.Key)
                        {
                          case nameof(settings.ApiKey):
                          int.TryParse(kv.Value, out int ApiKey);
                          settings.ApiKey=ApiKey;
                                break;
                            default:
                                break;
                           }
                       }
    
    

提交回复
热议问题