Cost of accessing a casted variable vs. assigning the casted variable? (C#)

01/05/2011 06:13 Lateralus#1
I know that in unmanaged C++, casting is at compile-time, so it's better to avoid the assignment and simply access it for all instances. However, in C#, I have no idea since I'm pretty new to it.
01/05/2011 10:36 Syst3m_W1z4rd#2
I know this is offtopic, but you need a link back on your site in signature, else is not allowed.
01/05/2011 10:39 Lateralus#3
Quote:
Originally Posted by Syst3m_W1z4rd View Post
I know this is offtopic, but you need a link back on your site in signature, else is not allowed.
I have a linkback, it's under advertising affliates. Unless I should state the location in my signature as well?

Any idea on the topic?
01/05/2011 13:45 Nullable#4
Assigning the casted variable would be better; because each cast to that variable would add another "castclass" instruction per cast.
01/05/2011 13:50 Lateralus#5
Quote:
Originally Posted by Nullable View Post
Assigning the casted variable would be better; because each cast to that variable would add another "castclass" instruction per cast.
Ah, I see. Thank you.
01/05/2011 16:05 IAmHawtness#6
Quote:
Originally Posted by Nullable View Post
Assigning the casted variable would be better; because each cast to that variable would add another "castclass" instruction per cast.
That said, casting objects/variables shouldn't really be THAT intense/time consuming for most CPUs, and the performance loss is measured in perhaps a few nanoseconds. I'd worry about a lot of other things before worrying about object casting performance.