三元运算符? [英] Ternary Operator?

查看:146
本文介绍了三元运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我只是好奇,如果有人知道.....

使用.NET 2,VB没有碰巧得到一个真正的三元运算符,做到了吗?坚持

远离某个角落?

三元,我的意思是像C''sa?b:c语法。

IIf的作品在大多数情况下,但在某些情况下你想要使用表达式

,如果它们不应该被评估,它们可能会失败,并且它会很好。写一个简洁的方式而不是使用整个

If-Then-Else块。


干杯全部,

- Arthur Dent。

Hi all, im just curious if anyone knows.....
With .NET 2, VB didnt happen to get a true ternary operator, did it? Stuck
away in a corner somewhere?
By ternary, i mean something like C''s a?b:c syntax.
IIf works in most cases, but in some instances you want to use expressions
which may fail if they are evaluated when they arent supposed to be, and it
would be nice to have a concise way of writing this instead of using a whole
If-Then-Else block.

Cheers all,
- Arthur Dent.

推荐答案

Arthur Dent写道:
Arthur Dent wrote:
大家好,我只是好奇,如果有人知道.....
使用.NET 2,VB没有碰巧得到一个真正的三元运算符,是吗?
被困在某个角落?
三元,我的意思是像C''sa?b :c语法。
IIf适用于大多数情况,但在某些情况下,你想使用
表达式,如果它们在它们不应该被评估时被评估可能会失败,并且它会很好有一个简洁的方法o写这个而不是使用整个If-Then-Else块。
Hi all, im just curious if anyone knows.....
With .NET 2, VB didnt happen to get a true ternary operator, did it?
Stuck away in a corner somewhere?
By ternary, i mean something like C''s a?b:c syntax.
IIf works in most cases, but in some instances you want to use
expressions which may fail if they are evaluated when they arent
supposed to be, and it would be nice to have a concise way of writing
this instead of using a whole If-Then-Else block.




也许你正在寻找AndAlso和OrElse进行评估

短路听起来就像你想要的那样。


如果错误,那么这个NeverGetsCalled()那么...


如果True OrElse thisNeverGetsCalled()那么...


Andrew



Perhaps you''re looking for AndAlso and OrElse which do the evaluation
short-circuiting it sounds like you want.

If False AndAlso thisNeverGetsCalled() then...

If True OrElse thisNeverGetsCalled() then...

Andrew


" Arthur Dent" <喜********************* @ yahoo.com> schrieb:
"Arthur Dent" <hi*********************@yahoo.com> schrieb:
使用.NET 2,VB没有碰巧得到一个真正的三元运算符,做到了吗?
离开某个地方的角落?
通过三元,我的意思是像C''sa?b:c语法。
With .NET 2, VB didnt happen to get a true ternary operator, did it? Stuck
away in a corner somewhere?
By ternary, i mean something like C''s a?b:c syntax.




VB'相当于


\\\

如果x那么

o = a

其他

o = b

结束如果

///


可以写成''如果x那么o = a Else o = b''。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http://classicvb.org/petition/>



VB''s equivalent is

\\\
If x Then
o = a
Else
o = b
End If
///

which can be written as ''If x Then o = a Else o = b''.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Arthur,


我不会像C那样告诉它,它是更老的语法

电子表格程序一切都必须在一个牢房里完成..


Cor


Arthur Dent <喜********************* @ yahoo.com> schreef in bericht

新闻:OB ************** @ TK2MSFTNGP11.phx.gbl ...
Arthur,

I would not tell this as like C, it is more syntax from older
spreadsheetprograms where everything had to be done in one cell..

Cor

"Arthur Dent" <hi*********************@yahoo.com> schreef in bericht
news:OB**************@TK2MSFTNGP11.phx.gbl...
大家好,我只是好奇,如果有人知道.....
使用.NET 2,VB没有碰巧得到一个真正的三元运算符,做到了吗?
离开某个地方的角落?
通过三元,我的意思是像C''sa?b:c语法。
IIf适用于大多数情况,但在某些情况下你想使用表达式
如果在它们不应该被评估时可能会失败,并且有一个简洁的方式来编写它而不是使用整个If-Then-Else将是很好的。阻止所有人,
- Arthur Dent。
Hi all, im just curious if anyone knows.....
With .NET 2, VB didnt happen to get a true ternary operator, did it? Stuck
away in a corner somewhere?
By ternary, i mean something like C''s a?b:c syntax.
IIf works in most cases, but in some instances you want to use expressions
which may fail if they are evaluated when they arent supposed to be, and
it would be nice to have a concise way of writing this instead of using a
whole If-Then-Else block.

Cheers all,
- Arthur Dent.



这篇关于三元运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆