Good practices for intialising properties ?

Posted by Rubans on Stack Overflow See other posts from Stack Overflow or by Rubans
Published on 2010-04-22T17:15:06Z Indexed on 2010/04/22 17:23 UTC
Read the original article Hit count: 297

Filed under:

HI, I have a class property that is a list of strings, List. Sometimes this property is null or if it has been set but the list is empty then count is 0. However elsewhere in my code I need to check whether this property is set, so currently my code check whether it's null and count is 0 which seems messy.

if(objectA.folders is null)
{
    if(objectA.folders.count == 0)
    {
      // do something
    }
}

Any recommendation on how this should be handled? Maybe I should always initialise the property so that it's never null? Appolgies if this is a silly question.

© Stack Overflow or respective owner

Related posts about c#