what is ctype ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 55555
    New Member
    • Dec 2009
    • 9

    what is ctype ?

    what is ctype ???
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      CType is used for when you want to Cast an object of a Type into a different Type in VB.NET

      In C# it's much easier. If you want to cast something into something else then you would just use:
      Code:
      Integer i;
      i = 5;
      
      Double j;
      j = (Double) i;
      This syntax cannot be used in VB.NET (probably because it uses brackets for so many things...arrays , functions etc) So, in VB.NET you either use the CType method or the DirectCast method to cast between object types:

      Code:
      Dim i As Integer 
      i = 5
      
      Dim j As Double = Ctype(i, Double)

      All the information you need on the CType method and any other .NET controls can be found in the MSDN Library. There are multiple articles on the CType Function there. I recommend bookmarking the MSDN Library and using it as your primary resource when developing in .NET.

      See How to: Define a Conversion Operator for a walk through on how to define a CType conversion operator (properly create the CType method) for your own custom classes!

      -Frinny

      Comment

      Working...