错误的输入字符串格式? [英] Wrong input string format?
本文介绍了错误的输入字符串格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string sCarID = lbl_carID.Text;
int carD = Int32 .Parse(sCarID);
//错误输入字符串的格式不正确。
解决方案
< blockquote>请尝试如下。
public static void Main()
{
int 数字;
string sCarID = 45跨度>;
bool result = Int32 .TryParse(sCarID, out number);
if (result)
{
Console.WriteLine( 将{0}转换为{1}。, 45,数字);
}
else {
Console.WriteLine( 失败跨度>);
}
}
现场演示: ideone
string sCarID = lbl_carID.Text;
int carD = Int32.Parse(sCarID);
//Error is Input string was not in a correct format.
解决方案
Please try is as below.
public static void Main() { int number; string sCarID="45"; bool result = Int32.TryParse(sCarID, out number); if (result) { Console.WriteLine("Converted '{0}' to {1}.", "45", number); } else{ Console.WriteLine("failed"); } }
LIVE DEMO : ideone
这篇关于错误的输入字符串格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文