2012-11-27 42 views
1

什么是最佳的解决方案是验证整数量。验证整个数字

我在考虑以下内容。

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

是否有更好的方法确保输入整数值?

+0

如果你不想使用标记验证并保持它在代码为你,可以考虑使用'Int32.TryParse'的http:// MSDN .microsoft.com/EN-US /库/ f02979c7.aspx –

回答

3

可以使用compare validator对于int验证

<asp:CompareValidator runat="server" Operator="DataTypeCheck" Type="Integer" 
ControlToValidate="youTextBoxID" ErrorMessage="Value must be a whole number" />