I have following data:
Dictionary<string,string> dctParameters = new Dictionary(){
{"a",var1},{"b",var2},{"c",var3},....
}
I want to join the "dctParameters" into a querystring.
What's the fastest / best among the following ways? Can you think you of a better way to do this?
1st method:
StringBuilder data = new StringBuilder();
string result = dctParameters.Aggregate(data, (x, pair) => data.Append(pair.Key).Append("=").Append(pair.Value).Append("&")).ToString();
2nd method:
StringBuilder data = new StringBuilder();
foreach (var item in dctParameters)
{
data.Append(string.Format("{0}={1}&",item.Key, item.Value));
}
string result = data.ToString();
3rd method:
StringBuilder data = new StringBuilder();
foreach (var item in dctParameters)
{
data.Append(item.Key).Append("=").Append(item.Value).Append("&");
}
string result = data.ToString();