Coalesce
There are a lot of long if statements that seem to be looking for the first usable value. (this is a composite of the idea...)
if (value1 != null)
variable = value1;
else if (value2 != null)
variable = value2;
else if (value3 != null)
variable = value3;
else
variable = DefaultValue;
Just to simplify and make more readable, try using the ?? (coalesce) operator. Notice the nullable type restrictions, etc.
variable = value1 ?? value2 ?? value3 ?? DefaultValue;
Inline If
Here is another one (again, just a composite)
if (something == somethingelse)
value = "1";
else
value = "2";
try making this one line, more readable.
value = (something == somethingelse) ? "1" : "2";
I know that these are some basic ideas, but judging by the code bases I have been checking out, they are not widely used. Perhaps, looking into some of these items as best practices would be beneficial.
الامانة كلين
ReplyDeleteشركة مكافحة الفئران فى دبى
شركة مكافحة البق فى دبى
شركة جلى وتلميع رخام فى دبى