Check if it is null

Discussion in 'ASP .Net' started by shapper, Oct 11, 2006.

  1. shapper

    shapper Guest

    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
     
    shapper, Oct 11, 2006
    #1
    1. Advertising

  2. 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

    --
    http://www.openmymind.net/
    http://www.fuelindustries.com/


    "shapper" <> wrote in message
    news:...
    > 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
    >
     
    Karl Seguin [MVP], Oct 11, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kivak Wolf
    Replies:
    2
    Views:
    10,118
    Kivak Wolf
    Jun 28, 2005
  2. vizlab
    Replies:
    3
    Views:
    4,277
    Michael Bar-Sinai
    Oct 17, 2007
  3. Replies:
    5
    Views:
    27,590
    Mike Schilling
    Mar 29, 2006
  4. G Fernandes
    Replies:
    9
    Views:
    630
    DHOLLINGSWORTH2
    Feb 27, 2005
  5. Mike
    Replies:
    12
    Views:
    747
    Daniel Pitts
    Sep 26, 2008
Loading...

Share This Page