整数解析

Sat*_*tiS 3 c#

我需要为一个值为<= 2147483647的文本框编写验证

我的代码是这样的:

Textbox1.Text = "78987162789"

if(Int32.Parse(Textbox1.text) > 2147483647)
{
  Messagebox("should not > ")
}
Run Code Online (Sandbox Code Playgroud)

我收到的错误信息如下:value is too small or too big for Int.我怎样才能解决这个问题?

pax*_*blo 5

有一种TryParse方法可以更好地实现这一目的.

int Val;
bool ok = Int32.TryParse (Textbox1.Text, out Val);
if (!ok) { ... problem occurred ... }
Run Code Online (Sandbox Code Playgroud)