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 first is better:
The second version returns
nullif the result of the call is not a string, but you know it always will be a string because theQueryStringmember has typeNameValueCollection. The indexer is defined to return astring: