Ionian316
Ionian316

Reputation: 2343

Why is String::IsNullOrEmpty() returning false in C++/CLI?

I have the following C++/CLI code:

String^ str = gcnew String("", 0, 10);
bool isEmpty = String::IsNullOrEmpty(str);

Why is String::IsNullOrEmpty() is returning false?

Upvotes: 2

Views: 1718

Answers (1)

Matt Smith
Matt Smith

Reputation: 17444

You are using this constructor (incorrectly):

public String(
    char* value,
    int startIndex,
    int length 
)

where

length 
    Type: System.Int32 
    The number of characters within value to use.

So, the length of your string is 10, and therefore, not empty.

Upvotes: 2

Related Questions