views:

2435

answers:

5

Hi guys, Can we use Coalesce operator(??) and conditional ternary operator(:) in VB.NET as in C#?

+4  A: 

I think you can get close with using an inline if statement:

//C#
int x = a ? b : c;

'VB.Net
Dim x as Integer = If(a, b, c)
Nick Josevski
*Note: using the if statement that way only applies in VB.NET 2008 and onwards.
Nick Josevski
+5  A: 

Discussed here and here

John Sheehan
A: 

'VB.Net Dim x as Integer = If(a, b, c) This code is not running. Giving an error as "There were build error"

Varsha
A: 

If should be IIf

Dim x as Integer=IIf(a,b,c)

Neelavardhan