Which of the following code is fastest/best practice for converting some object x?
int myInt = (int)x;
or
int myInt = Convert.T
Someone's already done the benchmarking. Here are the results. The fastest way if you know what you're converting will always be a valid int, is to use the following method (which a few people have answered above) :
int value = 0;
for (int i = 0; i < str.Length; i++)
{
value = value * 10 + (str[i] - '0');
}
Other techniques that were benchmarked were: