c# - Which one of these approaches to casting is the most effective? -
i have been wondering quite while now.
if(something mytype){ var item = mytype; }
or
var item = mytype; if(item != null){ }
the 2nd version
var item = mytype; if (item != null) { ... }
is better: one type conversion (as
) not 2 (is
, as
).
the 1st version (a bit modified) can used struct
not nullable:
// can't put "as" struct, i.e "something int" if (something int) { int item = (int) something; // note changed type conversion ... }
Comments
Post a Comment