You might also want to consider using the int.TryParse(string, out int)
method.
TryParse is a graceful approach to conversion because it returns a bool
indicating success or failure. If successful, the converted int is returned
in the out parameter.
string myStr = "123";
int myInt = int.MinValue;
if (!int.TryParse(myStr, out myInt)))
{
// conversion failed.
}
else
{
// conversion succeeded.
}
This saves your application from potential conversion exceptions.
Regards
Wole
"moondaddy" <mo*******@newsgroup.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
found it.
string myStr = "123"; int myParsedInt = Int32.Parse(myStr); int
myConvertedInt = Convert.ToInt32(myStr);
This example uses the int type, but you can also use the same techniques
for any of the other integral or floating point types.
[Author: Joe Mayo]
"moondaddy" <mo*******@newsgroup.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>How do I cast a string to an int?
Suto code:
string str = "1";
int i = (string)str;
Thanks.
--
mo*******@newsgroup.nospam