gpt4 book ai didi

c# - 当 TextBox.Text 不存在时,TextChanged 事件不会在 null 上触发

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:34 25 4
gpt4 key购买 nike

有谁知道为什么当我从 Textbox1 中删除所有文本时,它不会将其视为空值,而是将其视为空字符串?

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == null)
{
textBox2.Text = "Null";
}
else
{
textBox2.Text = "Input Positive";
}
}
}

最佳答案

null 不同于空字符串

private void textBox1_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox1.text))
{
textBox2.Text = "Null";
}
else
textBox2.Text = "Input Positive";
}

关于c# - 当 TextBox.Text 不存在时,TextChanged 事件不会在 null 上触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22552211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com