hog Posted March 18, 2003 Posted March 18, 2003 Can some explain in laymans terms the difference between the to convertion keywords please. I think I have it but just want to be sure. The help says Dim Q As Object = 2.37 Dim I As Integer = CType(Q,Integer) Dim J as Integer = DirectCast(Q,Integer) I succeeds as 2.37 converts to an Integer... J fails as Q was declared as an Object not an Integer so DirectCast fails. Question is why use DirectCast instead of CType Apologies incase this is a stupid question Quote My website
*Gurus* divil Posted March 18, 2003 *Gurus* Posted March 18, 2003 DirectCast is used to cast from one class to a sub or superclass of that type. The Convert class is used to convert one type to another, for example "3.141" to 3.141. The CType function is a VB helper designed to decide which one to use. I avoid it as it isn't available in any other language. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.