I have a collection of key/values in the form of a Dictionary<string, string>.
How would you convert or aggregate this into an attribute string:
key1="value1" key2="value2" key3="value3"
I believe this can be achieved using Aggregate function, however, I find the documentation on this particular extension method confusing. Any help is much appreciated.
I’d use:
.NET 4:
.NET 3.5 (where
string.Joinhas fewer overloads)If you need to do any escaping, do it in the
string.Formatcall. Of course, you don’t need to usestring.Format– you could use:It depends on which you find more readable. (The performance difference will be negligible.)