Lor*_*eno 0 .net c# dictionary
我有一本字典:
public Dictionary<string,Dictionary<string, Dictionary<DateTime, float>>> CPUResults = new Dictionary<string,Dictionary<string, Dictionary<DateTime, float>>>();
Run Code Online (Sandbox Code Playgroud)
现在,我想添加一些数据:
CPUResults.Add("KEY 1", new Dictionary<string, Dictionary <DateTime, float>>().Add("key 1", new Dictionary<DateTime,float>()));
Run Code Online (Sandbox Code Playgroud)
实际上,我不希望我的密钥是:密钥1,密钥2等等 - 只是不要复杂化我将这些密钥命名为这样.
好吧,重要的是,这不会编译.我不知道我做错了什么 - 我花了一段时间来提出这个,但它仍然没有用.
该Dictionary<TKey, TValue>.Add方法不返回字典.而是像这样初始化内部字典:
CPUResults.Add(
"KEY 1",
new Dictionary<string, Dictionary <DateTime, float>>
{
{ "key 1", new Dictionary<DateTime,float>() }
});
Run Code Online (Sandbox Code Playgroud)