首页 > 解决方案 > 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”

谁能给我一些建议,告诉我如何检查这个字符串是“”还是“”以外的东西?

标签: c#

解决方案


它应该是string.IsNullOrEmpty(text)

编辑 您需要使用上述内容,因为 string.IsNullEmpty() 是一种静态方法,您可以在静态方法中使用它。


推荐阅读