I'm trying to iterate over an unknown number of query values in C#... and can't find anything unrelated to LINQ, which I can't use. Anyone have any ideas?

Was it helpful?


If this question is about getting a querystring in ASP.NET, I think the link you are searching for is:

Essentially, Request.QueryString gives you a collection that you can then iterate over.


Using the Request.QueryString gives you a collection that you can iterate over. Using Request.QueryString.Allkeys allows you to iterate over a collection of strings that represent all of the keys i nthe query string. Using this we can come up with something like the below code in order to iterate over all keys and get their values.

foreach (string key in Request.QueryString.AllKeys)
    Response.Write("Key: " + key + " Value: " + Request.QueryString[key]);

Hope this helped.

If the collection implements IEnumerable you can use a foreach, otherwise use a for loop with the .Length of the collection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow