|
-
Jun 24th, 2003, 12:01 PM
#1
Thread Starter
Lively Member
Null, Nulls, Everywhere except my constructor
Ok, here is what I want to do, it is asp.net but that really shouldn't matter as my question is more on a class constructor.
I am trying to make my page load as slim as possible. So I have an Assembly(dll) that handles a lot of things for me. One such thing is the Cookie on user preferences.
which is easy enough to do.
My constructor is like this
public UserInfo(System.Web.HttpCookie UserCookie)
{
// code that reads the cookie info and populates the class
}
Anyway I can simply new this up and pass the cookie to it all in one line Like So
UserObject = new WebControls.CoreControls.UserInfo(Request.Cookies["UserPreference"]);
Ok so here is my problem
The Cookie doesn't exist on all visitors computers, if it doesn't exist you get a null reference execption.
Ok, So I know I can do a check to see if the cookie is null, if it is I call a different constructor, if it isn;t then I call the constructor you see above. What I want to know is how I can get rid of the if statement so that if it tries to pass a null it call another constructor.
public UserInfo(null UserCookie)
{
// this doesn't work since Null is not a valid datatype.
}
I am really just trying to get to a one line constructor. and one that can handle a null.
BTW Cookies are simply a collection object. so hopefully someone has dealt with passing a null to a constructor before.
The secret to creativity is knowing how to hide your sources.
-- Albert Einstein
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|