c# - Initializer syntax: new ViewDataDictionary { { "Name", "Value" } } -
i searching way pass viewdatadictionary partial view in asp.net mvc came syntax:
new viewdatadictionary { { "name", "value" } }
i'm bit confused initializer syntax here. can explain me?
viewdatadictionary
implements idictionary<string, object>
.
idictionary<string, object>
collection of keyvaluepair<string, object>
.
your viewdatadictionary
initializer (outer curly braces) contains set of curly braces represents keyvaluepair<string, object>
initializer.
the reason possible explained in this answer.
you can add multiple items comma separating keyvaluepair<string, object>
initializers:
var data = new viewdatadictionary { { "name", "value" }, { "name2", "value2" } };
same as:
var data = new viewdatadictionary { new keyvaluepair<string, object>("name", "value"), new keyvaluepair<string, object>("name2", "value2") };
essentially, inner curly braces nice syntax initializing keyvaluepair<string, object>
objects.
Comments
Post a Comment