c# - Can I speed up code by moving typeof out of loops? -


i have code executes typeof many times inside loops.

i'm wondering if should call typeof outside loops , use variable?

my code this.

for(int i=0; < 1000; i++) {     type t = foo(i);     if(t == typeof(string))     {         //....     } } 

is following code faster, slower or no difference?

type s = typeof(string) for(int i=0; < 1000; i++) {     type t = foo(i);     if(t == s)     {         //....     } } 

instead of running few c# tests see runs faster. i'm looking answer can explain happens when typeof used.

does produce compile time constant?

no (as in extremely negligible), typeof() done @ compile-time--the work type comparison. should asking why you're checking types when using polymorphism.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -