NameValueCollection x = new NameValueCollection(Request.QueryString);
string x1 = x.ToString();
NameValueCollection y = HttpUtility.ParseQueryString(Request.QueryString.ToString());
string y1 = y.ToString();
when I execute above code, value of x1 and y1 become
x1="System.Collections.Specialized.NameValueCollection"
y1="abc=1&xyz=2" //url pass to controller is 'localhost/first/getresult/?abc=1&xyz=2'
I don't understand why the value of x1 and y1 is different. I checked the documentation of ParseQueryString() and it show that it return NameValueCollection and I don't get any other information.
So, I don't understand why behavior is different of x and y.
In case of
HttpUtility.ParseQueryStringan instance of the classHttpValueCollectionis returned(source) which inherits fromNameValueCollection. Obviously this classs overridesToStringmeaningfully as opposed toNameValueCollectionwhich inheritsToStringfrom object, hence just diplays the full-type name.That's not mentioned in
ParseQueryStringbecauseHttpValueCollectionisinternal. They don't want you to use this type and you should not rely on this type being returned.Here's the source of
ToStringinHttpValueCollection: