Quantcast
Channel: Everyday I'm coding » vb.net
Viewing all articles
Browse latest Browse all 10

Is there a conditional ternary operator in VB.NET?

$
0
0

In Perl (and other languages) a conditional ternary operator can be expressed like this:

my $foo = $bar = $buz ? $cat : $dog;

Is there a similar operator in VB.NET?


Solution:

Depends. The If operator in VB.NET 2008 acts as a ternary operator. This was just introduced, prior to 2008 this was not available. Here’s some more info: Visual Basic If announcement

Example:

Dim foo as String = If(bar = buz, cat, dog)

Viewing all articles
Browse latest Browse all 10

Trending Articles