更新时间:2023-12-06 12:03:10
TextBox
仅包含字符串.如果需要数字值,则必须强制转换或解析Text
属性.我更喜欢解析:
ATextBox
contains only strings. You have to cast or parse theText
property if you want a numeric value. I prefer parsing:
int x;
if (int32.TryParse(textBox1.Text, out x))
{
// you have a valid integer
// and you can do what you want with x
}
else
{
// the text contains invalid characters
// put up an error message
}
您可以使用:
You can use this:
public int TextBoxValue
{
get
{
return int.Parse(TextBox.Text);
}
set
{
TextBox.Text = value.ToString();
}
}