错误!String.IsNullOrEmpty(s))

时间:2013-05-04 10:07:21

标签: c++-cli

这是c ++中的代码

List<String^> ^GetCodecs()
{
    List<String^> ^l = gcnew List<String^>;

    String ^s = gcnew String(Encoder_GetFirstCodecName());
    while (!String.IsNullOrEmpty(s))
    {
        l->Add(s);
        s = gcnew String(Encoder_GetNextCodecName());
    }

    return l;
 }

错误在线:

while (!String.IsNullOrEmpty(s))

在字符串

错误/ s都是关于字符串:

这是一个警告:

Warning 1   warning C4832: token '.' is illegal after UDT 'System::String'

错误:

Error   2   error C2275: 'System::String' : illegal use of this type as an expression
Error   3   error C2228: left of '.IsNullOrEmpty' must have class/struct/union
Error   4   error C1903: unable to recover from previous error(s); stopping compilation
Error   5   IntelliSense: type name is not allowed

我该如何修复它们?

1 个答案:

答案 0 :(得分:3)

由于IsNullOrEmpty是一个静态函数,您可能需要使用::运算符调用它:

while (!String::IsNullOrEmpty(s))