Outputting a manipulated QueryString in C#

HttpValueCollection is internal, but you can use "var" to declare it without extract it with reflector.

var query = HttpUtility.ParseQueryString(Request.Url.Query);
query["Lang"] = myLanguage; // Add or replace param
string myNewUrl = Request.Url.AbsolutePath + "?" + query;

You can also use Reflector to extract the HttpValueCollection class into your own, and use it then.


Because it is actually a special NVC that is of type HTTPValueCollection. So when you call .ToString on it, it knows how to format it correctly.