0

Is it simply a matter of preference or is there any good reason to use one over the other.. performance wise?? :

string x = (serialNbr != "")?serialNbr:String.Empty;

vs.

string x;
if(serialNbr == "")
{
    x = String.Empty;
}
else
{
    x = serialNbr;
}
psj01
  • 3,075
  • 6
  • 32
  • 63
  • 1
    performance shouldn't be your first concern. sometimes the ?: operator makes code more easy to read, and that's good enough. – Sam I am says Reinstate Monica Jun 08 '16 at 18:15
  • Pro: ?: Can be used straight in assignments which can make code more terse and concise. Con: ?: Can be used straight in assignments which can make code more complex if there are multiple levels of embedded conditions. – aggaton Jun 08 '16 at 19:08

0 Answers0