C# || operator to VB

  • Thread starter Thread starter hansiman
  • Start date Start date
Looks like a logical OR to me...

Dim Result As Boolean = (aDataset Is Nothing) Or (aDataset.Tables.Count = 0)

Sets Result to true if aDataset is Nothing or if there are zero tables in
aDataset
Sets Result to false if aDataset has been initialized or if it has at least
one table.
 
Actually Ken that's not quite right. Your code would fail if aDataSet is
Nothing because both clauses are evaluated and nothing cannot be evaluated.
The more precise transation would be to use the OrElse statment, which short
circuits if aDataSet is nothing, therefore the second clause would not be
evaluated and there would be no error.

Dim Result as Boolean = IsNull(aDataSet) OrElse (aDataSet.Tables.Count = 0)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
 
Actually, it's an OrElse as it's short-circuit

You should always be using OrElse when doing logical comparisons instead of
Or...or should only be used as a bit operator..

Karl
 
Ha!

I should have known better than to hazard a response about C#! Thanks Steve
for setting it straight.

Ken
 
thanks a lot :-)

Ehhh. I'm using IsDbNull not IsNull - seem to work.

NB I enjoy your aspnetpro column.
 
Thanks Karl! From now on I'll leave the C# questions to the guys who know
it! <grin>
 
Well, there IS one other exception to that rule, Karl. If you have a
specific reason for needing to evaluate BOTH experssions (such as function
calls that return booleans, but must be made), you should also use the Or
operator.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
Kevin:
My personal opinion is that this leads to
hard-to-read-gonna-cause-problems-down-the-road code. Far better to nest
the if statement in those rare instances. But ur right..it could be used
for that.

Karl
 
I agree this leads to hard-to-read code that is prone to errors, and
therefore should be avoided.
This was the argument for having Or function like OrElse does (so that
OrElse wouldn't be necessary) but that battle was lost.
:-(
 
Well, heck guys, I only said that you could. Just covering all the bases.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
Don't worry Kevin, we weren't ganging up on you!
We agree with you. We just didn't want folks to go thinking it was a good
idea to go with that kind of design. But you probably already knew that.
 
I understand, Steve. :)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
Back
Top