I'm not sure if it's ok to ask this kind of question here, but I just want to know the difference between the two code snippets.
As I was browsing the questions here in SO, I found this post: How to find the number of HTML elements with a name that starts with a certain string in c#?
a user answered this:
var dictionary = Request.Form.Keys
.Cast<string>()
.Where(x => x.StartsWith("abc"))
.ToDictionary(x => x, x => Request.Form[x]);
Returns a dictionary containing the keys/values for all form elements that start with "abc".
Update: The poor OP is using .Net 2.0. So here is the old-school answer:
Dictionary<string, string> keys = new Dictionary<string, string>();
foreach (string key in request.Form.Keys)
{
if (key.StartsWith("abc"))
keys[key] = request.Form[key];
}
Which of the two is faster in execution or is more optimized? Should we never use the old one?