2010-03-15 19 views

Respuesta

87

Es TryCast:

Dim x As String = TryCast(y, String) 
If x Is Nothing Then ... 
+3

+1 Aunque creo 'TryCast' no es exactamente ** * * equivalente a 'as' porque' TryCast' no funciona para tipos de valor? – MarkJ

+7

@Mark: El operador * as * tampoco funciona en tipos de valores en C#. –

+2

Bueno, esto funciona para tipos de valores que aceptan valores numéricos ... Usted puede hacer: var x = y como int ?; if (x == null) ... por lo que debería poder hacer Dim x = TryCast (y, System.Nullable (Of Integer)) en VB – JoelFan

4

Dim x = TryCast (y, [String])

6

TryCast:

Dim x = TryCast(y, String) 
if (x Is Nothing) ... 
8

Trycast es lo que estás buscando.

Dim x = TryCast(y, String) 
3

Aquí van:

código C#:

var x = y as String; 
if (x == null) ... 

VB.NET equivalentes:

Dim x = TryCast(y, String) 
If (x Is Nothing) ... 
Cuestiones relacionadas