Is Convert.ToInt or Convert.ToUint plugged?

Jan 29, 2012 at 1:59 AM

Hey guys it seems that my toint code for a string is slow

Code:

 public int ConvertToInt(string number)
        {
            for (int i = 0; i < 9999; i++)
            {
                if (i.ToString() == number)
                {
                    return i;
                }
            }
            return 0;
        }
And because it is slow, I was wondering if Convert.ToInt was plugged or Convert.ToUint, cause that would help. If not maybe I could help. Thanks - Matt

Developer
Jan 29, 2012 at 2:11 AM
Edited Jan 29, 2012 at 2:12 AM

use Int32.Parse(number) instead.

Jan 29, 2012 at 2:22 AM
blah38621 wrote:

use Int32.Parse(number) instead.

Oh ok, thanks Orvid. Thanks - Mat