SomeObject* obj = FunctionThatReturnsSomeObject();if ( obj ) DoSomethingWithSomeObject( obj );
SomeObject obj = FunctionThatReturnsSomeObject();if ( obj != null ) DoSomethingWithSomeObject( obj );
// Don't need to brace around a single statement if clauseif ( obj != null ) DoSomethingWithSomeObject( obj );// You do need braces around single statement try/catch/finally blockstry{ DoSomethingWithSomeObject( obj );}catch ( Exception ex ){ MessageBox.Show( "obj is null!" );}finally{ if ( obj != null ) obj.Dispose();}
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.