I need to pass html attributes.
It is possible to pack into one expression code some like this?
var tempDictionary = new Dictionary<string, object> {
{ "class", "ui-btn-test" },
{ "data-icon", "gear" }
}.Add("class", "selected");
or
new Dictionary<string, object> ().Add("class", "selected").Add("diabled", "diabled");
?
What you are referring to is known as method chaining. A good example of this is the StringBuilder’s
Appendmethod.This is possible because the Append method returns a
StringBuilderobjectBut, in your case, the Add method of
Dictionary<TKey, TValue>is marked voidTherefore, method chaining is not supported. However, if you really wanted to use method chaining when adding new items, you could always roll your own:
Then you could write the following code: