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.
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.Quote:
Assigning the casted variable would be better; because each cast to that variable would add another "castclass" instruction per cast.