mardi 2 novembre 2021

How to check if the string does not contain one of the two values using c# operators?

I am reading a file data as follows:

string cellData = _reader.GetField("name").ToLower();

I would like to check if cellData is not equal to true or false as string.

I have tried the following:

if (cellData != "true" || cellData != "false") { }

The problem with the above code will always return true.

so what I did I created an array and then used contains:

string[] boolValues = { "true", "false" };

if (!boolValues.Contains(cellData)) { //error }

is it possible to check using c# operator if the string does not contains the word true or false than return error if it contains one of them that it should not return an error using single line if statement

Aucun commentaire:

Enregistrer un commentaire