1

最好的解决方案是验证整数数量。

我在想以下几点。

double value = Double.Parse(txtCubes.Text);
    double wholeValue = Math.Round(value);
Console.WriteLine("You added " + wholeValue + " blocks of ice");

是否有更好的原因确保输入整数值?

4

1 回答 1

3

您可以使用比较验证器进行 int 验证

<asp:CompareValidator runat="server" Operator="DataTypeCheck" Type="Integer" 
 ControlToValidate="youTextBoxID" ErrorMessage="Value must be a whole number" />
于 2012-11-27T15:09:02.073 回答