VB.Net - TryCast

This is a type of explicit conversion
If this conversion is not possible a Nothing value is returned.
This is a type of conversion operator that does not throw an exception.


Dim myText As String
myText = TryCast(myNumber, String)


If you try to do a coversion with DirectCast or CType and it fails an InvalidCastException is thrown.
Instead of generating an exception this operator return Nothing
This operator can only be used with reference types


C# Equivalent

??


VBA

This operator is not available in VBA.


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext