【发布时间】:2015-06-11 08:07:27
【问题描述】:
我在将字符串转换为整数时遇到问题,我的程序在这一行失败了
int newS = int.Parse(s);
带消息:
在 mscorlib.dll 中发生了“System.FormatException”类型的未处理异常
我期望从我的程序中返回的数字相当大。以下是总程序:
int math = (int)Math.Pow(2,1000);
string mathString = math.ToString();
List<string> list = new List<string>();
char[] ch = mathString.ToCharArray();
int result = 0;
foreach (char c in mathString)
{
string newC = c.ToString();
list.Add(newC);
//Console.WriteLine(newC);
}
foreach (string s in list)
{
int newS = int.Parse(s);
result += newS;
}
Console.Write(result);
Console.ReadLine();
【问题讨论】:
-
你有没有看过 mathString 是什么?如果 2^1000 大于 32 但 int 可以处理,我很确定,所以我不确定类型转换会做什么,但可能不是你想要的。
-
你不应该使用
BigInteger吗?
标签: c#