转换像"09335887170"到一个整数

本文关键字:quot 一个 整数 09335887170 转换 | 更新日期: 2023-09-27 18:12:06

如何将像"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());

转换像"09335887170"到一个整数

Int32(或仅int)的最大值为2,147,483,647你需要UInt64Int64Long

string a = "09335887170";
Int64 myInt;
bool isValid = Int64.TryParse(a, out myInt);
if (isValid)
{
    int plusOne = myInt + 1;
    MessageBox.Show(plusOne.ToString());
}
result = Convert.ToInt64(value);

点击这里查看更多信息。

这个数字超过了最大int值。

试试这个

Int64  no = Convert.ToInt64(  "09335887170");