Conditional Using
April 9th, 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?


