It depends on what you want to convert it FROM.
(int)x doesn't work for a string-x, int.Parse
*only* works on strings.
You could try it yourself with a small program:
- Remember System.DateTime.Now
- do the conversion a lot of times (100.000)
- get a fresh DateTime.Now
- subtract the times.
Repeat a couple of times to get an average value.
string str = "1";
int i = Convert.ToInt32(str ); //this will work
int i = (int) str //this won't work
so you aren't comparing apples to apples
secondly, any difference would be so absolutely minor and any major
differences would be so specific to a given situation, no one could
accurately answer save the person asking...
when passing in a string, Convert.ToInt32() simply calls int.Parse...it's
actually a bit slower, because it does a null check...but that also makes it
100% better to use if you ask me...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.