Описание тега directcast
DirectCast is a keyword in VB.NET for explicitly changing the type of an expression, but only via class inheritance or interface implementation.
The DirectCast
keyword is one of three type change operators in Visual Basic. It only applies changes due to class inheritance or interface implementation. Compared to the other two, DirectCast
is faster and simpler than CType
but does not apply the conversions available with the latter, and TryCast
is only for reference types but otherwise applies the same changes as DirectCast
, which throws an InvalidCastException
at runtime if the cast cannot be performed.
Q: Casting DataTypes with DirectCast, CType, TryCast
Q: Difference between DirectCast() and CType() in VB.Net