In C#, which one is faster?
The direct cast doesn't have to do any checking except a runtime type check - I would expect that the cast is quicker.
You might also want to consider objThatIsString.ToString()
; since (for string
) this is just return this;
, it should be quick - certainly quicker than the Convert.ToString
. Then the race is between a runtime type-check and a virtual call; in reality, both are very, very quick.