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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -