I need explanations.. I using C#.NET to web applications, I always write:
string val = Request.QueryString["foo"];
and then
if(!string.IsNullOrEmpty(val))
What's the difference:
string val = Request.QueryString["foo"];
I was advised to do:
string val = Request.QueryString["foo"] as string;
if(!string.IsNullOrEmpty(val))
What's the difference?
The request query parameter names are case-sensitive.
The order of parameters matters in query strings. In the following example, the query strings are identical except that the parameters are in a different order.
Request. QueryString. Count != 0 will simply tell you if there are no parameters at all.
Query string values can be checked using regular expressions. You can select regular expressions from the global White list or enter them manually. For example, if you know that a query string must have a value of ABCD , a regular expression of ^ABCD$ is an exact match test.
The first is better:
string val = Request.QueryString["foo"];
The second version returns null
if the result of the call is not a string, but you know it always will be a string because the QueryString
member has type NameValueCollection
. The indexer is defined to return a string
:
public class NameValueCollection : NameObjectCollectionBase
{
// ...
public string this[string name] { get; set; }
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With