FormatException 即使字符串格式正确也会发生错误

问题描述 投票:0回答:1

总结的代码是这样的。

string savedTextValue1 = PlayerPrefs.GetString(TextValueKey1).ToString();
print(savedTextValue1.GetType()+ savedTextValue1+savedTextValue1+savedTextValue1);
int.Parse(savedTextValue1);

输出为

系统.String303030 FormatException:输入字符串的格式不正确。

我认为字符串格式是正确的。我添加了这一行

savedTextValue1 = "30";

在打印()之前 测试一下是否有效,没有报错。 为什么我会收到 FormatException 错误?

c# unity-game-engine unityscript formatexception
1个回答
0
投票

执行以下操作

print(savedTextValue1.GetType().ToString() + savedTextValue1.ToString() +
      savedTextValue1.ToString() + savedTextValue1.ToString());

您不能在不同类型上使用

+
并期望串联。
+
是每种类型的不同运算符,并且对于每种类型的行为都不同。对于许多人来说,它甚至没有定义

© www.soinside.com 2019 - 2024. All rights reserved.