Blog

Conditional Using

April 9, 2009

Today I found myself writing the following code:

private void DoSomething(String userName)
{
    using(var userEntry = GetUserEntryFor(userName))
        if(CouldBeFound(userEntry))
    {
        // Do something with userEntry                
    }
} 

private DirectoryEntry GetUserEntryFor(String userName)
{
    // ...        
} 

private static Boolean CouldBeFound(DirectoryEntry entry)
{
     return null != entry;
}

Notice the combination of the if statement with the using statement. I thought this was kind of neat. What do you think?

Is the style of this code bonafide?

Profile picture of Jan Van Ryswyck

Jan Van Ryswyck

Thank you for visiting my blog. I’m a professional software developer since Y2K. A blogger since Y2K+5. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.

Comments

About

Thank you for visiting my website. I’m a professional software developer since Y2K. A blogger since Y2K+5. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.

Contact information

(+32) 496 38 00 82

infonull@nullprincipal-itnull.be