By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,334 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,334 IT Pros & Developers. It's quick & easy.

Checking Validity of uninitialized object

P: n/a
I have a struct that I am creating an object for but not initializing
it. Later on under certain conditions it gets
set to the values of another struct. However I have to check this
struct for an valid instance and sometimes it is
not a valid instance and gives an exception. Since I cannot use a null
for a value type how would I check for the
validity of the object.

For example:

one.cs contains
in a loop :
myObject firstInstance;

if firstInstance is valid then

setvals ();

second.cs contains:
firstInstance = validInstance;

May 16 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
You need an "isValid" boolean or something like it in your struct. The
CLR guarantees that when your struct is first created all booleans will
be "false".

If you are using .NET 2.0 then you can get this same effect by using
the "?" suffix to your type, e.g.:

myStruct? firstInstance;

will create a "nullable" struct.

May 16 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.