Directcast and CType are still a bit different

xiaoxiao2021-03-06  40

difference:

Just define valid conversions between expressions and types,

Ctype can be successful,

and

DirectCast requires the runtime type of the object variable as the specified type.

performance:

If the specified type of the expression is the same, the runtime type is the same.

Directcast's runtime performance ratio

Ctype's runtime performance is good.

DIM Q as Object = 2.37 'Requires option strict to be off.

DIM I as integer = ctype (q, integer) 'succeeds.

DIM J AS INTEGER = Directcast (q, integer) 'Fails.

转载请注明原文地址:https://www.9cbs.com/read-54765.html

New Post(0)