-2

I have to query array of strings from SQL using this code:

defaultMail = getDefaultMailList(requester);

and the sql query string is

SELECT * FROM dbo. ....

Then, I get array of string from the getDefaultMailList method:

string toEmail = defaultMail[0];
string ccEmail = defaultMail[1];

Then, I use the value of SQL query to make a condition of if else like this.

if (ccEmail != "")
{
    do something
}

Now, I met the problem when SQL query returns null value. The ccList != "" still returns TRUE, but I want to make it return FALSE.

How to handle with this problem?

Thank you.

armyjam
  • 11
  • 5

1 Answers1

2

To check if it's empty or null you can use the IsNullOrEmpty Function. This function will both check if the variable is null or empty.

If you want to check user input you could also use IsNullOrWhitespace, which additionally checks if the string consists of only whitespace characters.

// Check if the string is either empty or null.
if (string.IsNullOrEmpty(ccList))
{
    // do something
}
IndieGameDev
  • 2,905
  • 3
  • 16
  • 29