如何将字符串“09335887170”转换为整数?这是我曾尝试过的:将字符串“09335887170”转换为整数
string a = "09335887170";
int myInt;
bool isValid = int.TryParse(a, out myInt); // it returns false in this case
if (isValid)
{
int plusOne = myInt + 1;
MessageBox.Show(plusOne.ToString());
}
MessageBox.Show(a);
int stringToInt = Convert.ToInt32("09335887170"); // it returns nothing with no error
MessageBox.Show((stringToInt + 1).ToString());
int test = int.Parse(a); //it has type convertion error
MessageBox.Show((test + 1).ToString());
这个数字对于一个整数来说太大了。你有没有考虑过使用很长时间? –
签出Long或BigInteger。另外为了获取详细信息,只需使用“解析” - 方法来获得明确的例外。 –
1.使用正常的'Parse' 2.运行代码并得到一个错误3. Google错误信息....然后你会得到你的解决方案,然后问这个问题要容易得多 – musefan