我正在寻找如何在vb.net的两行中编写if else语句。我不是指三元运营商,尽管这可能有用。如果... elseif,else语句在三行(或者如果在其他两行)
例如,我想这样做
if x = y then matching = true
elseif x < y then ygreater = true
else xgreater = true
我发誓,我见过这样的事情之前,可能使用了“:”操作符。
任何帮助将是伟大的,谢谢。
我正在寻找如何在vb.net的两行中编写if else语句。我不是指三元运营商,尽管这可能有用。如果... elseif,else语句在三行(或者如果在其他两行)
例如,我想这样做
if x = y then matching = true
elseif x < y then ygreater = true
else xgreater = true
我发誓,我见过这样的事情之前,可能使用了“:”操作符。
任何帮助将是伟大的,谢谢。
我想你可以使用:标志分割线:
If x = y Then matching = True: ElseIf x < y Then ygreater = True: Else xgreater = True: End If
但是,为什么?
没有理由,实际上很重要,只是为了缩短方法。 – Kosko
intInput = x
Select Case intInput
Case y
matching = true
Case IS < y
ygreater = true
Case Else
xgreater = true
End Select
在C#.NET,你需要使用 “案例1:”(也许你意味着:)
不知道为什么,但在这里不用
If x <= y Then If x < y Then ygreater = True Else matching = True Else xgreater = True
证明
Dim y As Integer
Dim ygreater, xgreater, matching As Boolean
y = 1
Debug.WriteLine("")
For x As Integer = 0 To 2
Debug.WriteLine("X = {0} Y = {1} ", x, y)
ygreater = False
xgreater = False
matching = False
If x <= y Then If x < y Then ygreater = True Else matching = True Else xgreater = True
Debug.WriteLine("X > {0} Y > {1} Match {2}", xgreater, ygreater, matching)
Next
它为什么它有多少行? – Jon
说实话,它确实没什么,只是格式化而已。我只想简化一些基本的陈述,但不太喜欢三元运算符。 – Kosko