Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

In VB, I believe the following are equivalent:

If Not x = y Then
...
End If

and

If x <> y Then
...
End If

Am I wrong? Is there some scenario in which they are not equivalent? If so, what is it? If not, is one preferred over the other? Why? In the latter, the <> operator is pretty foreign looking to me, as I am more used to the C# !=. I also end up forgetting if it is <> or >< all the time. The downside of the former seems to be that it reads like Yoda speaks.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Using Not x = y is like using !(x==y) in C# instead of just using x!=y.

Use <>. Lack of comfort with a language's syntax is a poor excuse for knowingly using it improperly.

FYI, <> is used in SQL. VB.Net isn't the only language that uses it.

share|improve this answer
    
Good point. I hadn't really thought about the example you gave but it makes perfect sense. I would never use !(x==y) in C#. –  jtheis Feb 14 '13 at 19:09
    
Interestingly, != seems to work in T-SQL as well. –  Jesse C. Slicer Feb 14 '13 at 19:19
    
@JesseC.Slicer: True, but != is not ansi compliant, so <> is preferable. –  Brian Feb 14 '13 at 21:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.