Best Practice on IF/ELSE Statement Order

前端 未结 10 2252
陌清茗
陌清茗 2020-12-16 14:48

Which is a better practice? (I\'m coding in .Net if that makes a difference)

IF condition = true THEN
   ...true action--even if rare...
ELSE
   ...action
E         


        
10条回答
  •  情话喂你
    2020-12-16 15:36

    Go with the most readable version for your specific case, and by the way, don't compare a boolean expression to true and false. Use condition and Not condition (!condition in C#.)

    if (condition == true) // bad
    if (condition) // better 
    

提交回复
热议问题