TryCast - VB.Net

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 x As String
x = TryCast(y, 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



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