C# nested dictionaries
问题 What is wrong with my syntax? I want to be able to get the value "Genesis" with this info["Gen"]["name"] public var info = new Dictionary<string, Dictionary<string, string>> { {"Gen", new Dictionary<string, string> { {"name", "Genesis"}, {"chapters", "50"}, {"before", ""}, {"after", "Exod"} }}, {"Exod", new Dictionary<string, string> { {"name", "Exodus"}, {"chapters", "40"}, {"before", "Gen"}, {"after", "Lev"} }}}; 回答1: You cannot define a class field using var . Change var to Dictionary