I m pretty new to C# and ASP.NET, so bear with me on this one. I m setting up a page that receives query strings from the url. It then passes these strings to another method (in another class, actually), which goes on to do lots of things depending on the value of the query string.
The general structure looks something like this, where DoSomething()
is actually part of another class that will be used by lots of different pages:
pretected void Page_Load (object sender, EventArgs e)
{
DoSomething (Request.QueryString["name"]);
}
public void DoSomething (string UrlVariable)
{
// if UrlVariable isn t set, initialize it to some value
// do stuff with UrlVariable
}
Here s what I m wondering:
- If the query string "name" isn t defined in the url, what does Request.QueryString return? an empty string?
null
? - If it returns
null
, what happens if I try to passnull
to a method that is expecting a string? Does the whole program fall apart, or can I check fornull
inside the DoSomething() method (after receiving the null string)?
The "name" is optional, so if the user doesn t set it, I d like to detect that and initialize it to some default value. If possible, though, I d like to put any validation inside DoSomething(), instead of doing the check on every page that requests the string.
Thanks in advance!