Yeah, you're right. I sometimes to that because I don't exactly know whether the == / != operators have been overloaded correctly, in case they have been overloaded (and whether they also work on null values).

I removed the cast, and changed the whole logic to the ?-operator.