Is there a function in the system.convert namespace that equals the ctype function ?
For example the Cdbl function is equal to the system.convert.todouble function.
Printable View
Is there a function in the system.convert namespace that equals the ctype function ?
For example the Cdbl function is equal to the system.convert.todouble function.
System.Convert.ChangeType(object, typetochangeto)
Give me an example.
I have this piece of code:
Dim objControl As Control
Dim objPicBox As PictureBox
objPicBox = CType(objControl, PictureBox)
Show me how to do ....
you can still use ctype.
Dim objControl As Control
Dim objPicBox As PictureBox
objPicBox = CType(objControl, PictureBox)
i believe that will work!?!
But i could be wrong, i do use it in my current application though
What's wrong with just using CType?
you use it the EXACT same way as CType
one reason not to use CType is that it is a part of the Microsoft.VisualBasic namespace that was added for backwards compatability. I myself try to avoid it becuase it is 1 less reference I need since that dll provides me nothing I cant do with the standard .NET classes.
Hey Cander,
did you ever try this ?
Check it out and you will see that it can't be used in the same way.
system.convert.changetype(objControl, PictureBox) does not work !
So try it and tell me how to do ... ( if you can )
hmm no I didnt try it, but according to the win class viewer, that is all you should have to do. Ill have to try it tomorrow when I get back to work.
ohh.try this
System.Convert.ChangeType(objcontrol, TypeOf(PictureBox))
maybe that will work..I dont have .NET where I am now, so I cant test.
That's not true. There's absolutely nothing wrong with using that namespace. The one to avoid that's there for backwards compatibility is the Microsoft.VisualBasic.Compatibility namespace.Quote:
Originally posted by Cander
one reason not to use CType is that it is a part of the Microsoft.VisualBasic namespace that was added for backwards compatability.
The Microsoft.VisualBasic namespace is an integral part of the VB.NET language. Check the documentation. Nowhere does it say that it's only for backwards compatibility. There's also a Microsoft.CSharp namespace. Is that one supposed to be for backwards compatibility, too?
Also, CType isn't even found in Microsoft.VisualBasic to begin with. This quote is straight out of Microsoft's documentation:
This means that all these substitutes you people are cooking up are actually slower.Quote:
CType is compiled inline, meaning the conversion code is part of the code that evaluates the expression. Execution is faster because there is no call to a procedure to accomplish the conversion.
CType is just VB.NET's implementation of casting. There's no reason to avoid it, just like there's nothing wrong with this line in C#:
int i=(int)longVariable;
TypeOf(PictureBox) does not work
Ok Im a retard! :(Quote:
Originally posted by Tygur
Also, CType isn't even found in Microsoft.VisualBasic to begin with. This quote is straight out of Microsoft's documentation:
This means that all these substitutes you people are cooking up are actually slower.
CType is just VB.NET's implementation of casting. There's no reason to avoid it, just like there's nothing wrong with this line in C#:
int i=(int)longVariable;
I had assumed it was part of the backwards compat namespace....
is there any option to put off the visual basic namespace so i just can't use its functions? it would be a good way to me get used to dont use it anymore
I found out something interesting today. The compiler already refs that namespace built into it, so it raelly doesnt matter.
Yes! Just Right-Click on your project name in the Solution Explorer, then select Properties - Imports. In the “Project Imports:” list, delete Microsoft.VisualBasic. I strongly recommend adding the Microsoft namespace so that you don't have to include "Microsoft." in front of everything from the VisualBasic namespace. I did this early on in the program that I'm working on and I've NEVER regretted it. No more accidental MsgBox's for this guy :)Quote:
Originally posted by PT Exorcist
is there any option to put off the visual basic namespace so i just can't use its functions? it would be a good way to me get used to dont use it anymore