Coalesce statement and conditional statement in VB.NET

Possible duplicate:
Is there a conditional ternary operator in VB.NET?

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

+11
conditional-operator null-coalescing-operator
Mar 10 '09 at 5:35
source share
4 answers

I think you can come close to using the inline if statement:

//C# int x = a ? b : c; 'VB.Net Dim x as Integer = If(a, b, c) 
+14
Mar 10 '09 at 5:52
source share
 Sub Main() Dim x, z As Object Dim y As Nullable(Of Integer) z = "1243" Dim c As Object = Coalesce(x, y, z) End Sub Private Function Coalesce(ByVal ParamArray x As Object()) Return x.First(Function(y) Not IsNothing(y)) End Function 
+12
Mar 06 2018-11-11T00:
source share

for reference only, Coalesce operator for String

 Private Function Coalesce(ByVal ParamArray Parameters As String()) As String For Each Parameter As String In Parameters If Not Parameter Is Nothing Then Return Parameter End If Next Return Nothing End Function 
+3
Nov 04 '10 at 9:13
source share

If there should be IIf

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

-3
Sep 16 '10 at 17:01
source share



All Articles