2011-03-04 6 views
1

if else文をvb.netの2行に書く方法を探しています。私は三元演算子を意味するわけではありませんが、それはうまくいくかもしれません。 「:」演算子if ... elseif、else else statement on 3行(または2つの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 

しかし、なぜ:行を分割するために署名:

+0

それは何行あるのですか? – Jon

+0

正直言って、それは実際にはdoens't、それは実際にフォーマットするだけです。私はちょうどいくつかの基本的なelse文についてlinecountを落としたいと思っていて、三項演算子が本当に好きではありません。 – Kosko

答えて

3

私はあなたが使うことができますね?

+0

実際に重要な理由はありません。短い方法を作るだけです。 – Kosko

1

行継続文字_を使用すると、その1行の文を3行に分割できます。

あなたが使用する必要があるC#.NETで
+0

これらの2つの答えを組み合わせることは、私が探しているものです。ありがとうございます! – Kosko

0
intInput = x 
Select Case intInput 
    Case y 
     matching = true 
    Case IS < y 
     ygreater = true 
    Case Else 
     xgreater = true 
End Select 

"CASE 1:"(多分あなたは

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 
を行く:)ことを意味