「VB.NET」三項演算子のサンプル

2021年10月4日

書式
IF(条件式, Trueの場合の返却値, Falseの場合の返却値)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module Module1
Sub Main()
Dim age As Integer = 21
Dim str As String = "study"
'三項演算子 条件付き判定
Dim result As String = If(age >= 20, "AA", "BB")
Dim result2 As String = If(Len(str) >= 10, "CC", "Dd")
Console.WriteLine("三項演算子の判定結果1: " + result.ToString)
Console.WriteLine("三項演算子の判定結果2: " + result2.ToString)
Console.ReadKey()
End Sub
End Module
Module Module1 Sub Main() Dim age As Integer = 21 Dim str As String = "study" '三項演算子 条件付き判定 Dim result As String = If(age >= 20, "AA", "BB") Dim result2 As String = If(Len(str) >= 10, "CC", "Dd") Console.WriteLine("三項演算子の判定結果1: " + result.ToString) Console.WriteLine("三項演算子の判定結果2: " + result2.ToString) Console.ReadKey() End Sub End Module
Module Module1


    Sub Main()

        Dim age As Integer = 21
        Dim str As String = "study"

        '三項演算子 条件付き判定
        Dim result As String = If(age >= 20, "AA", "BB")

        Dim result2 As String = If(Len(str) >= 10, "CC", "Dd")

        Console.WriteLine("三項演算子の判定結果1: " + result.ToString)

        Console.WriteLine("三項演算子の判定結果2: " + result2.ToString)


        Console.ReadKey()

    End Sub

 
End Module

結果
三項演算子の判定結果1: AA
三項演算子の判定結果2: Dd

VB.net

Posted by arkgame