Conditional or in C #

I have been programming in JAVA and C all my years in Uni, but now I am learning C # and building a small application, and I found problems with this:

if (taxonType.Equals(null) ¦¦ taxonID == -1)

I get a red underline for this conditional expression, and I really don’t know why, because according to what I saw, it should be good, but it’s not. Is something missing?

Thank you all in advance, Victor


Thanks everyone !!! I was mad at it. The fact is, I'm Spanish, and I'm used to having a pipe wrench | exactly in the same place where | is in the American configuration ... I saw it is strange, but I thought it was the same ...

Thanks for the quick response!! Victor

+5
source share
9 answers
if (taxonType == null || taxonID == -1)

Changed for the correct code, as well as to answer the question asked

+11

"|"? , , "|"?

+5

taxonType taxonID, :

if (taxonType == null || taxonID == -1) 
+4

, , (|). , ?

+2

, taxonType Null, .Equals NullReferenceException. == Equals

+2

taxonType , , Equals.

if (taxOnType == null) || taxonID == -1), .

+2

"||" "||".

+1

Your test for null should not be used .Equals, because if the object is null, an attempt to access the member will call NullReferenceException.

Using:

if (taxonType == null || taxonID == -1) 

It is also unclear whether you are using the correct channel symbol |, since your is displayed as ¦.

+1
source

if (String.IsNullOrEmpty (taxonType) || taxonID <0)

and make a taxon like STRUCT

+1
source

All Articles