且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#||运算符到VB

更新时间:2022-11-16 19:07:23

对我来说看起来像逻辑OR ...


Dim Result As Boolean = (aDataset is Nothing)或(aDataset.Tables.Count = 0)


如果aDataset为Nothing或者

中有零表,则将Result设置为true aDataset

如果aDataset已初始化或者一张表至少有
,则将结果设置为false。


" hansiman" ; <公顷*** @ hotmail.com>在消息中写道

news:7k ******************************** @ 4ax.com ...
on http: //www.bsdg.org/2005/01/empty-dataset.shtml
我遇到了这个C#代码:

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

我想我知道它应该做什么!
这是如何用VB编码的




其实Ken确实不太对劲。如果aDataSet是
你的代码会失败,因为这两个子句都被评估,没有任何东西无法评估。

使用OrElse语句进行更精确的转换, br />
电路如果aDataSet什么都没有,那么第二个子句将不会被评估为
并且没有错误。


昏暗的结果as Boolean = IsNull(aDataSet)OrElse(aDataSet.Tables.Count = 0)

-

我希望这有帮助,

Steve C. Orr,MCSD,MVP
http://SteveOrr.net

" Ken Cox [Microsoft MVP]" < BA ************ @ sympatico.ca>在消息中写道

新闻:大江************** @ tk2msftngp13.phx.gbl ...
看起来像逻辑或给我...

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

如果将结果设置为true aDataset是Nothing或者如果
中有零表aDataset
如果aDataset已初始化或者它至少有一个表,则将Result设置为false。

" ; hansiman" <公顷*** @ hotmail.com>在消息中写道
新闻:7k ******************************** @ 4ax.com ... on http:// www。 bsdg.org/2005/01/empty-dataset.shtml
我遇到了这个C#代码:

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

我想我知道它应该做什么!
这是如何用VB编码的



实际上,它是一个OrElse,因为它的短路


在做逻辑时你应该总是使用OrElse比较而不是

或...或者只应该用作位运算符..


Karl


-

我的ASP.Net教程
http:/ /www.openmymind.net/

" Ken Cox [Microsoft MVP]" < BA ************ @ sympatico.ca>在消息中写道

新闻:大江************** @ tk2msftngp13.phx.gbl ...
看起来像逻辑或给我...

Dim Result As Boolean =(aDataset Is Nothing)或(aDataset.Tables.Count =
0)
如果aDataset为Nothing或者将Result设置为true或者如果aDataset中有零表格
如果aDataset已经初始化或者如果它在
至少有一个表格,则将结果设置为false。

hansiman <公顷*** @ hotmail.com>在消息中写道
新闻:7k ******************************** @ 4ax.com ... on http:// www。 bsdg.org/2005/01/empty-dataset.shtml
我遇到了这个C#代码:

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

我想我知道它应该做什么!
这是如何用VB编码的



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

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.

"hansiman" <ha***@hotmail.com> wrote in message
news:7k********************************@4ax.com...
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




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
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
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.

"hansiman" <ha***@hotmail.com> wrote in message
news:7k********************************@4ax.com...
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



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/
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
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.

"hansiman" <ha***@hotmail.com> wrote in message
news:7k********************************@4ax.com...
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