Groups | Blog | Home
all groups > asp.net > february 2005 >

asp.net : C# || operator to VB


Steve C. Orr [MVP, MCSD]
2/7/2005 2:57:46 PM
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


[quoted text, click to view]

Ken Cox [Microsoft MVP]
2/7/2005 5:50:13 PM
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.

[quoted text, click to view]
Karl Seguin
2/7/2005 6:00:25 PM
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

--
MY ASP.Net tutorials
http://www.openmymind.net/


[quoted text, click to view]

Ken Cox [Microsoft MVP]
2/7/2005 6:09:26 PM
Ha!

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

Ken

[quoted text, click to view]
Ken Cox [Microsoft MVP]
2/7/2005 6:10:16 PM
Thanks Karl! From now on I'll leave the C# questions to the guys who know
it! <grin>


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
[quoted text, click to view]
hansiman
2/7/2005 11:42:40 PM
on http://www.bsdg.org/2005/01/empty-dataset.shtml
I came across this C# code:

bool Result = ( aDataset == null ) || ( aDataset.Tables.Count == 0 );

I think I know what it is supposed to do!
How is this coded in VB
hansiman
2/8/2005 12:09:29 AM
thanks a lot :-)

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

NB I enjoy your aspnetpro column.

On Mon, 7 Feb 2005 14:57:46 -0800, "Steve C. Orr [MVP, MCSD]"
[quoted text, click to view]
Kevin Spencer
2/8/2005 8:16:07 AM
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.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
[quoted text, click to view]

Steve C. Orr [MVP, MCSD]
2/8/2005 3:25:47 PM
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.
:-(

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
[quoted text, click to view]

Karl Seguin
2/8/2005 6:15:21 PM
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
--
MY ASP.Net tutorials
http://www.openmymind.net/


[quoted text, click to view]

Kevin Spencer
2/9/2005 7:51:57 AM
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.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
[quoted text, click to view]

Steve C. Orr [MVP, MCSD]
2/9/2005 12:41:51 PM
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 hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


[quoted text, click to view]

Kevin Spencer
2/9/2005 4:51:12 PM
I understand, Steve. :)

--
HTH,

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

[quoted text, click to view]

AddThis Social Bookmark Button