VB.NET equivalent of C# "As"
What is the equivalent in VB.NET of the C# As keyword, as in the following?
var x = y as String;
if (x == null) ...
Solution 1:
It is TryCast:
Dim x As String = TryCast(y, String)
If x Is Nothing Then ...
Solution 2:
Trycast is what you're looking for.
Dim x = TryCast(y, String)
Solution 3:
TryCast:
Dim x = TryCast(y, String)
if (x Is Nothing) ...
Solution 4:
Here you go:
C# code:
var x = y as String;
if (x == null) ...
VB.NET equivalent:
Dim x = TryCast(y, String)
If (x Is Nothing) ...
Solution 5:
Dim x = TryCast(y, [String])