I try to construct an instance of Dictionary<string, Dictionary<string, string>>
in this way,
Dictionary<string, Dictionary<string, string>> PredictiveTable =
new Dictionary<string, Dictionary<string, string>>(){
{"+", new Dictionary<string, string>() {"E","error"}},
{"*", new Dictionary<string, string>() {"E","error"}},
{"i", new Dictionary<string, string>() {"E","E->TK"}},
{"(", new Dictionary<string, string>() {"E","E->TK"}},
{")", new Dictionary<string, string>() {"E", "error"}},
{"#", new Dictionary<string, string>() {"E", "error"}}
};
but the compiler just tell the error messages
CS7036 C# There is no argument given that corresponds to the required formal parameter 'value' of Dictionary<'string, string>.Add(string, string)
And I try to search the error tips before, but just can't find a way to solve it.
I will be sincerely appreciated if anyone could help me.
Dictionary<string, Dictionary<string, string>> PredictiveTable =
new Dictionary<string, Dictionary<string, string>>(){
{"+", new Dictionary<string, string>() {{"E","error"}}},
{"*", new Dictionary<string, string>() {{"E","error" }}},
{"i", new Dictionary<string, string>() {{ "E","E->TK"}}},
{"(", new Dictionary<string, string>() {{"E","E->TK"}}},
{")", new Dictionary<string, string>() {{"E", "error"}}},
{"#", new Dictionary<string, string>() {{ "E", "error"}}}
};
new Dictionary<string, string>()
expects a collection of KeyPairValues for the initialization (like you did for the outer Dictionary). You passed only one.
So
new Dictionary<string, string>() {"E","error"}
becomes
new Dictionary<string, string>() {
{"E","error"}
}
Try to follow this syntax.
In your code, you are missing {} brackets while initializing sub dictionary with values. The same you did for out Dictionary but not in inner.
Dictionary<string, Dictionary<string, string>> dict = new Dictionary<string, Dictionary<string, string>>() {
{"Key1", new Dictionary<string, string>() { { "SubKey1","Value1"} } },
{"Key2", new Dictionary<string, string>() { { "SubKey2","Value2"} } }
};
After following this, your Dictionary will look like
Dictionary<string, Dictionary<string, string>> PredictiveTable =
new Dictionary<string, Dictionary<string, string>>(){
{"+", new Dictionary<string, string>() {{"E","error"}}},
{"*", new Dictionary<string, string>() {{"E","error" }}},
{"i", new Dictionary<string, string>() {{ "E","E->TK"}}},
{"(", new Dictionary<string, string>() {{"E","E->TK"}}},
{")", new Dictionary<string, string>() {{"E", "error"}}},
{"#", new Dictionary<string, string>() {{ "E", "error"}}}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With