Check if it is null

S

shapper

Hello,

I have 3 different properties in a class. The properties are of types:

Mail.MailPriority, Mail.MailAddress and Mail.MailAddressCollection

I wan to check if the properties were defined, i.e., if they are null
or not.

I was able to work this out for properties of type boolean and string
but not for these ones.

Could someone help me out?

Thanks,

Miguel
 
K

Karl Seguin [MVP]

Well, MailPriority is an enum of base type int32...by default int's default
to 0... so you can't check if it's null. It'll always be atleast set to
MailPriority.Normal (which is 0).


For MailAddress and MailAddressCollection you can do check if they are null
like:

if (mailAddress == null)
{
//!!it's null
}


same thing with MailAddressCollection, but you can also check if it's Count
== 0

if (mailAddressCollection== null || mailAddressCollection.Count == 0)
{
//it's null
}


in vb.net:

if mailAddress is nothing then


and instead of || use "OrElse"

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top