0 Members and 1 Guest are viewing this topic.
if ( some_condition ){ do_this();}else{ do_that(); }
if ( some_condition ) do_this();else do_that();
if ( XrLock == null ) XrDb.Dispose();else XrLock.Dispose();
foreach ( KeyValuePair<string, AnnotationScale> kvp in ScDict ) ScCntxCol.RemoveContext( kvp.Key );
I use both.But lately started to leave the braces, since end up adding more lines in between, something that can be done very easy later, but also to keep all on the same.But that's me.
if (some_condition) { do_this(); do_this_too(); } else { do_that(); }
if (some_condition) { do_this(); do_this_too(); } else do_that();
For the most part I don't use the extra braces, however, I keep them symmetrical I.e.
if (some_condition){ do_this(); do_this_too(); }else { do_that(); }
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); if( !bt.Has(blockName) ) { ed.WriteMessage("\nBlock '{0}' is not available in the current drawing.", blockName); return; } PromptPointResult ppr = ed.GetPoint("\nSpecify insertion point: "); if( ppr.Status != PromptStatus.OK ) return;
get { return doc; } set { doc = value; if( doc == null ) { db = null; ed = null; } else { db = doc.Database; ed = doc.Editor; } }
if (x >= 0) if (x > 0) PositiveX();else // Oops! Matches most recent if! NegativeX();
I purchased 'The Elements of C# Style' a few years ago and it's an excellent book - I generally live by it when writing C# code.As far as this discussion is concerned, Rule No. 12 is invoked (this is an extract) - 'Always use Block Statements in Control Flow Constructs' to avoid the 'dangling else' problem ...
I find when going over code I haven't worked on in a while, its easy to skip right over a single line of unbraced "else" code when there is a large block of "if-positive" code right above it. For internal consistency I only omit the braces where both are single-statements. If either require multiple lines they both get braced.
Hi, MichaelI have read in "Best code practice" article , don't remember where is it, but written by one of the giants ( I think by Petzold, not sure about )"Better yet to use the brackets always"