Question: Hi i need to pass my Request.Form as a parameter, but first i have to add some key/value pairs to it. I get the exception that the Collection is readonly.

I've tried:

```
System.Collections.Specialized.NameValueCollection myform = Request.Form; 

```

and i get the same error. 

and i've tried:

```
foreach(KeyValuePair<string, string> pair in Request.Form)
{
     Response.Write(Convert.ToString(pair.Key) + " - " + Convert.ToString(pair.Value) + "<br />");
}

```

to test if i can pass it one by one to another dictionary, but i get:

> 
> System.InvalidCastException: Specified
>  cast is not valid.
> 
> 
> 

some help, anyone? Thanx

Answer: 
You don't need to cast a `string` to `string`. `NameValueCollection` is built around string keys, and string values. How about a quick extension method:

```
public static IDictionary<string, string> ToDictionary(this NameValueCollection col)
{
  var dict = new Dictionary<string, string>();

  foreach (var key in col.Keys)
  {
    dict.Add(key, col[key]);
  }

  return dict;
}

```

That way you can easily go:

```
var dict = Request.Form.ToDictionary();
dict.Add("key", "value");

```
```
public static IEnumerable<Tuple<string, string>> ToEnumerable(this NameValueCollection collection)
{
    return collection
      //.Keys
        .Cast<string>()
        .Select(key => new Tuple<string, string>(key, collection[key]));
}

```

or

```
public static Dictionary<string, string> ToDictionary(this NameValueCollection collection)
{
    return collection
      //.Keys
        .Cast<string>()
        .ToDictionary(key => key, key => collection[key]));
}

```