The HttpRequest.QueryString object is already a collection. Basically, the name is ValueCollection. Check here for a more detailed explanation on MSDN. To convert this collection to a dictionary, you can add an extension method as follows.
public static class NameValueCollectionExtension { public static IDictionary<string, string> ToDictionary(this NameValueCollection sourceCollection) { return sourceCollection.Cast<string>() .Select(i => new { Key = i, Value = sourceCollection[i] }) .ToDictionary(p => p.Key, p => p.Value); } }
Then you could just do the following, since Request.QueryString is basically a NameValueCollection
IDictionary<string,string> dc = Request.QueryString.ToDictionary();
source share