In VB.NET CType can be used to convert one type to another.
CType(expression,type)
I have the "expression" stored in an instance object class, say "objExp"
.
I have the "type" stored in an instance of Type class, say"objType"
.
I am trying CType(objExp, objType)
I am getting compile error, how should I go about it ? "objType
" is fetched and assigned at runtime.
Have you looked into the method CTypeDynamic()? The second parameter (ie: The Type) can be set dynamically. Great for when you are using Reflection.
For example:
CTypeDynamic(strValueToConvert, objTypeToConvertTo)
This is simply not possible. The CType
expression must be passed a Type
instance which is known at compile time like Integer
, String
, etc ... It does not accept values which are of type Type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With