C# - 与"IsNullOrWhiteSpace"相反的是什么?

And*_*ard 1 c#

我使用带有"IsNullOrWhiteSpace(+ textbox)"的if条件来引用一个没有值或只有空格的文本.但是,现在我需要知道hot指定一个非空或仅空白的字段.

这是我写的代码:

if (string.IsNullOrWhiteSpace(pathofsrcfilesTOCOPY.Text))
Run Code Online (Sandbox Code Playgroud)

但是,如果我想指定只在textfield为null或为空时运行命令呢?

非常感谢您的帮助.我是初学者.感谢帮助.

祝你有美好的一天!

use*_*620 8

string.IsNullOrWhiteSpace如果文本为null或空格,则返回true.如果返回值为false,则文本将填充非空白字符.

使用找出条件不正确的位置!.

if (!string.IsNullOrWhiteSpace(pathofsrcfilesTOCOPY.Text))
Run Code Online (Sandbox Code Playgroud)

这相当于:

if (string.IsNullOrWhiteSpace(pathofsrcfilesTOCOPY.Text) == false)
Run Code Online (Sandbox Code Playgroud)

如果pathofsrcfilesTOCOPY.Text填充了非空白文本,则上述两个都将进入if语句.