【发布时间】:2019-06-30 18:06:02
【问题描述】:
我有一个简单的文本框TextChanged 事件,用于检查用户在字段中输入的字符串。
private void Phone_TextChanged(object sender, TextChangedEventArgs e)
{
string phone = Phone.Text;
if (phone.Length > 2 && phone.Length < 6)
{
string digit = Convert.ToString(phone[phone.Length - 1]);
bool isNumeric = int.TryParse(digit, out int n);
if (!isNumeric)
{
phone = phone.Substring(0, phone.Length - 1);
Phone.Text = phone;
}
}
}
但是当我尝试编译它时,我在Phone.Text = phone; 线上得到了System.StackOverflowException。我尝试将Substring() 更改为Remove(),但仍然出现此错误。我不知道是什么问题。
【问题讨论】: