This blog defines the Ternary operator in VB.NET.

Ternary operator

The general syntax of the Ternary operator in VB.NET.

Code
If(question, expression1, expression2)
Code
Here question(?) is the condition if condition is true, then expression1 will be execute otherwise expression2 will be execute.

The general syntax of the Ternary operator in C#.NET.

Code
question ? expression1 : expression2

It can be rewritten the above Syntax :

Code
if (question =true){
   expression1;
}else {
   expression2;
}
Code
For example
Code
C# code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication42

{

class Program

{

static void Main(string[] args)

{

int i = 3;

int j = 2;

Console.WriteLine(i > j ? i : j);

}

}

}

Code
VB code

Module Module1

Sub Main()

Dim i As Integer = 3

Dim j As Integer = 2

Console.WriteLine(If(i > j, i, j))

End Sub

End Module

OUTPUT


b1.gif