如何初始化字典列表

Mig*_*ier -1 .net c# generics

如何使用集合初始化器初始化对象System.Collections.Generic.ListSystem.Collections.Generic.Dictionary

Mig*_*ier 6

List<Dictionary<string, object>> listaDeDicionarios = new List<Dictionary<string, object>>()\n{\n    new Dictionary<string,object>()\n    {\n        {"chave1","valor um"},\n        {"chave2","dois"},\n        {"chave3",true}\n    },\n    new Dictionary<string,object>()\n    {\n        {"chave4",4},\n        {"chave5",DateTime.Now},\n        {"chave6",long.MaxValue},\n        {"chave7","..."}\n    },\n    new Dictionary<string,object>()\n    {\n        {"chave8","utf string \xc3\xa1\xc3\xa9\xc3\xad / &url"},\n        {"chave9",null},\n        {"chave10",String.Empty},\n        {"chave11",new List<string>(){"aaa","bbb","ccc","oh my god, it\'s a miracle!"}}\n    }\n};\n
Run Code Online (Sandbox Code Playgroud)\n

  • 您应该编辑问题并将此代码添加到其中。 (4认同)
  • @maniak1982:为什么?回答你自己的问题是完全可以的,并且受到鼓励。 (3认同)