【发布时间】:2013-11-26 17:47:45
【问题描述】:
在将一些代码从我的测试项目转移到以 Windows CE 为目标的“真实”项目时,一些代码在 IDE 中变得尴尬并变红,即“TryParse()”。
由于缺少……马蹄铁,战斗失败了;希望 TryParse() 的缺失不会导致类似healthcare.gov 的eCatastrophe;然而,有没有比 TryParseless 解析器重写 TryParse() 更好的方法:
int recCount = 0;
string s = "42";
try {
recCount = Int32.Parse(s);
}
catch {
MessageBox.Show("That was not an int! Consider this a lint-like hint!");
}
?
【问题讨论】:
-
如果
s是一个字符串,那永远不会成功。事实上,它甚至不会编译,因为编译器可以 100% 确定它永远不会成功。 -
真;我更改了它,但我的问题还是一样:鉴于 WindowsCE 目标的限制,是否有一种不那么笨拙的方法来实现这一点?
标签: c# casting windows-ce tryparse target-platform