Coding Without If else
|
|
|
Question / Problem
|
How to avoid if else statements in most situation. and improve coding style
|
Solution
|
Case 1 - Boolean Variables
//Boolean Control.Enabled = value; Invert Control.Enabled = !value;
Case 2 - Other Variables
//Number Control.Enabled = (value== valueToCompare);
//String Control.Enabled = (String.Compare(value , “Value to check”) == 0);
Case 3 – Assign multiple possible values
Control.CssClass = (value== valueToCompare ? “Value 1” : “Value 2”)
Case 4 – Search
Control.Enabled = value.Contains(, “Value to check”);
|
Applies to |
|
C# 2005
,Core Java, .Net 2.0 Windows Forms, PHP
|
Rank It |
|