Page 1 of 1

toInt32

PostPosted: Thu Sep 26, 2013 12:42 pm
by relez
Just another question:

in C# ToInt32 accept string as argument. But if i try:

num = int.toInt32("123")

i get:

error: Argument 1 of method "toInt32" expects type IFormatProvider?, but the call is supplying type String.

What am i missing?

Re: toInt32

PostPosted: Thu Sep 26, 2013 1:48 pm
by nerdzero
Not sure what's going on there. Maybe it has something to do with explicitly implemented interfaces? http://msdn.microsoft.com/en-us/library ... int32.aspx (scroll down to the methods).

Regardless, you can use this instead I believe:
num = Convert.toInt32("123")


edit:
This will work too if you are sure the string is a number:
num = int.parse("123")

Re: toInt32

PostPosted: Thu Sep 26, 2013 2:23 pm
by relez
Yep, int.parse works fine and it was my first choice.... i was just curious about toInt32....
Anyway .Net presents Convert.ToInt32 Method (Object, IFormatProvider) as well... so i agree it could an implementation issue.
Thx.