Check if it is null

  • Thread starter Thread starter shapper
  • Start date Start date
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
 
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
 
Back
Top