Rex*_*x_C 14 .net c# asp.net null
有问题的文本框涉及我的代码中的if语句,这是有效的
if (textbox.text != "")
{
do this
}
Run Code Online (Sandbox Code Playgroud)
我很好奇,如果一个空文本框将被视为空字符串或空语句.
PSL*_*PSL 27
尝试使用IsNullOrWhiteSpace,这将确保验证空白,而不必修剪它.
if (!string.IsNullOrWhiteSpace(textbox.Text))
{
//code here
}
Run Code Online (Sandbox Code Playgroud)
根据文件string.IsNullOrWhiteSpace评估:
return String.IsNullOrEmpty(value) || value.Trim().Length == 0;
Run Code Online (Sandbox Code Playgroud)
指示指定的字符串是空,空还是仅包含空格字符.
| 归档时间: |
|
| 查看次数: |
69991 次 |
| 最近记录: |