在VB.Net中是否有条件If的形式? [英] Is there a form of conditional If in VB.Net?

查看:386
本文介绍了在VB.Net中是否有条件If的形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim i,j,k As Integer

i = 2:j = 3


如果我> j然后

k = i

否则

k = j

结束如果


有办法做这样的事吗

k =(i> j)?我:j


谢谢,

Rich

Dim i, j, k As Integer
i = 2 : j = 3

If i > j Then
k = i
Else
k = j
End If

is there a way to do something like this
k = (i > j) ? i : j

Thanks,
Rich

推荐答案



" Rich" <日** @ discussions.microsoft.com>在消息中写道

news:92 ********************************** @ microsof t.com ...

:Dim i,j,k作为整数

:i = 2:j = 3



:如果我> j然后

:k = i

:否则

:k = j

:结束如果



:有没有办法做这样的事情

:k =(i> j)?我:j



:谢谢,

:Rich

k = Iif(i> j,i ,j)

Ralf

"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
: Dim i, j, k As Integer
: i = 2 : j = 3
:
: If i > j Then
: k = i
: Else
: k = j
: End If
:
: is there a way to do something like this
: k = (i > j) ? i : j
:
: Thanks,
: Rich
k = Iif(i > j, i, j)
Ralf


" Rich" <日** @ discussions.microsoft.com> schrieb:
"Rich" <Ri**@discussions.microsoft.com> schrieb:
Dim i,j,k As Integer
i = 2:j = 3

如果我> j那么
k = i
否则
k = j
结束如果

有办法做这样的事情
k = (i> j)?我:j
Dim i, j, k As Integer
i = 2 : j = 3

If i > j Then
k = i
Else
k = j
End If

is there a way to do something like this
k = (i > j) ? i : j




''IIf''。但是,请注意''IIf''是一个函数,因此将评估两个部分(true

part和false part)。除此之外,如果打开'Option Strict'',则需要施放
。 VB 2005将支持一个

泛型版本的''IIf'',它将使用强类型,这将消除

需要进行投射。

-

MS Herfried K. Wagner

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

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



''IIf''. However, note that ''IIf'' is a function and thus both parts (true
part and false part) will get evaluated. In addition to that, casting will
be required if ''Option Strict'' is turned on. VB 2005 will suppport a
generic version of ''IIf'' which will work strongly-typed, which removes the
need of casting.

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


谢谢。我刚尝试过,但是当Option Strict打开时出现问题 -

表示


Option Strict不允许将系统对象隐式转换为整数 ;


我也试过

k = IIF(m> n,Ctype(m,整数),Ctype(n,整数)


它也不喜欢。我也试过Imports Microsoft.VisualBasic,但

也没有这样做。我不想转选项严格。有没有

a这个方法?


谢谢


" _AnonCoward"写道:
Thanks. I just tried that, but having a problem when Option Strict is on -
says

"Option Strict does not allow implicit conversion of system object to integer"

I also tried
k = IIF(m > n, Ctype(m, Integer), Ctype(n, integer)

It didn''t like that either. I also tried Imports Microsoft.VisualBasic, but
that didn''t do it either. I don''t want to turn off Option Strict. Is there
a way around this?

Thanks

"_AnonCoward" wrote:

" Rich"< Ri ** @ discuss.microsoft.com>写在消息中
新闻:92 ********* ************************* @ microsof t.com ...
:Dim i,j,k As Integer
:i = 2:j = 3

:如果我> j那么
:k = i
:其他
:k = j
:结束如果

:有没有办法做这样的事情
:k =(i> j)?i:j

:谢谢,
:Rich

k = Iif(i> j,i,j)

Ralf

"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
: Dim i, j, k As Integer
: i = 2 : j = 3
:
: If i > j Then
: k = i
: Else
: k = j
: End If
:
: is there a way to do something like this
: k = (i > j) ? i : j
:
: Thanks,
: Rich
k = Iif(i > j, i, j)
Ralf



这篇关于在VB.Net中是否有条件If的形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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