In some utility libraries I have methods that have a params[] parameter. In many of these cases, these end up as key/value pairs which would be even more useful if I could convert these to a dictionary.
What would be the most efficient method to do this? Can I do this via Linq somehow?
Here is an example:
public static Uri appendParams(Uri uri, params string[] parameters)
{
if (uri == null)
{
return null;
}
if (parameters == null) {
return uri;
}
var queryStringBuilder = new StringBuilder(uri.Query ?? "");
//Would like to convert the params[] argument to a dictionary here
Dictionary<String, String> paramsDictionary = null; // Not sure best way to do this...
foreach (KeyValuePair<String, String> kvp in paramsDictionary)
{
queryStringBuilder.Append(kvp.Key + "=" + kvp.Value);
}
var uriBuilder = new UriBuilder(uri);
uriBuilder.Query = queryStringBuilder.ToString();
return uriBuilder.Uri;
}