18
Mar 11

Ternary operator in VB.net

For about months ago I started working in a amazing company in Norway called OMEGA as Application Developer / Systems Engineer.

VB.net (winforms) is one of the platforms we use.

Since I come mainly from the world of Java, PHP and ActionScript, It’s been a constant learning process in which it is impossible not to compare features among technologies.

Today I was wondering how do the ternary conditional operator works in VB. I remember I use the “?:” operator in Java in Order to assign the value to a variable according to the result of a conditional operator.

This is what I found:

Java:

String resultMsg =  MyVar1 == MyVar2?"The Variables are equal":"The variables are NOT equal";

VB.Net

Dim resultMsg as String = IF(MyVar1 = MyVar2, "The Variables are equal","The variables are NOT equal")

Best!