c# - IsNullOrEmpty' 在当前上下文中不存在
问题描述
我有这个代码:
public static FormattedString AddParagraph(this FormattedString formattedString, string text)
{
if (IsNullOrEmpty(text))
return formattedString;
else
{
formattedString.Spans.Add(new Span { Text = text + Environment.NewLine + Environment.NewLine, ForegroundColor = Color.FromHex("555555") });
return formattedString;
}
}
但它告诉我:当前上下文中不存在名称“IsNullOrEmpty”
谁能给我一些建议,告诉我如何检查这个字符串是“”还是“”以外的东西?
解决方案
它应该是string.IsNullOrEmpty(text)
编辑 您需要使用上述内容,因为 string.IsNullEmpty() 是一种静态方法,您可以在静态方法中使用它。
推荐阅读
- excel - Excel - 使用切片器根据列更改数据透视图
- swift - @_downgrade_exhaustivity_check Swift 私有关键字是什么?
- c# - 如何在选择行时获取单元格 GridView Devexpress 以进行编辑
- java - cvc-complex-type.2.4.a:发现以元素“位置”开头的无效内容
- gitlab - 如何在 GitLab 上上传文件?
- svn - 提交到多个 svn 外部时的灰色复选框
- python - 如何将恢复图的输出张量连接到张量流中默认图的输入?
- regex - 从同一行和下一行获取值
- python - 将值添加到 Python 列表中的一系列值的最有效方法是什么?
- json - 将所有 JSON 字符串转换为 JSON