An Error That I have Recently Completed

An Error That I have  Recently Completed 

编写C#应用程序时,用到了TextBox文本输入框。

当需要判断文本框输入是否为空时写成了if (textBox_id.Text.ToString() == Null)

应该用textBox_id.Text.ToString() == ""

Reason of the error

没有认清Null和""的区别。

Null指没有定义,内存没有分配空间

""是空字符串,系统分配了空间,但是字符串为空

Impact of the error

并程序不能正确判断出输入框输入为空。

即使输入框内没有任何输入,也没有执行输入框为空之后的操作而是判断为输入框有输入。

因为textBox_id.Text.ToString() == Null 一直为假。

How did I find it

 程序failure。测试时没有输出预期结果。

posted @ 2016-05-04 16:43  xltju  阅读(123)  评论(0)    收藏  举报