how well do you know VB (part 2)
Posted
Thu, Jul 20 2006 0:06
by
bill
a few weeks ago,
I posted a quiz about the syntax low < x < high, which really was a quiz about implicit casting of Booleans. Of course the great
Dan Appleman got that one right :)
That quiz stemmed from an
earlier post, and raised some questions about values of Booleans in general. I plan to post a long explanation, but first I thought I'd have some more fun with syntax quizzes :)
Given the following conditions:
- Code is compiled with Strict On and Explicit On rules applied
- two variables are declared as follows:
Dim x As Boolean = SomeFunctionthatReturnsABoolean()
Dim y As Boolean = True
Do all the following evaluate to the same If condition ? We're not concerned over how they get there, but whether or not they all get to the same place.
(1) If x = y Then
(2) If x And y Then
(3) If x <> Not y Then
(4) If Boolean.Equals(x,y) Then
Remember, y is specified as being True in all these expressions.
Are they all the same, always ?