Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET equivalent of C# "As"

Tags:

.net

vb.net

What is the equivalent in VB.NET of the C# As keyword, as in the following?

var x = y as String; if (x == null) ... 
like image 836
JoelFan Avatar asked Mar 15 '10 20:03

JoelFan


People also ask

Is there a operator in VB net?

In VB.NET, operator is a special symbol that tells the compiler to perform the specific logical or mathematical operation on the data values. The data value itself (which can be either a variable or a constant) is called an operand, and the Operator performs various operations on the operand.

What is operator C#?

Operators are symbols that are used to perform operations on operands. Operands may be variables and/or constants. For example, in 2+3 , + is an operator that is used to carry out addition operation, while 2 and 3 are operands. Operators are used to manipulate variables and values in a program.

What is equivalent to C#?

It is enharmonically equivalent to D-flat major. Its key signature has seven sharps.

What is assignment operator in VB net?

Simple assignment operator, Assigns values from right side operands to left side operand. C = A + B will assign value of A + B into C. += Add AND assignment operator, It adds right operand to the left operand and assigns the result to left operand.


2 Answers

It is TryCast:

Dim x As String = TryCast(y, String) If x Is Nothing Then ... 
like image 107
Hans Passant Avatar answered Oct 12 '22 08:10

Hans Passant


Trycast is what you're looking for.

Dim x = TryCast(y, String) 
like image 26
Morten Anderson Avatar answered Oct 12 '22 06:10

Morten Anderson