CType

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Todd Plambeck

    #1

    CType

    Is there a more C# like alternative to CType? I don't like using the
    VB6esque "C" conversion methods(CStr, CInt, etc) . I'd prefer to user
    something like Convert.ToInt32 (), but can't find a equivalent for converting
    objects.

    Thanks,

    Todd


  • Cor Ligthert [MVP]

    #2
    Re: CType

    Todd,

    I don't know why you want to use all posibilities you get. However you can
    use in VBNet any System.Net methods as you use in C# as long as it is not
    C# unsave code.

    (The same as you can use in C# every Microsoft.Visua lBasic namespace method
    in C#)

    Therefore Convert.ToInt32 is the same in Visual Basic in Net as it is in C#.

    If you don't want to use CInt that is your choise, if you like to type more
    characters I won't keep you from doing that. I just type Cint as it is a
    valid Net method. (Not a system.net namespace method by the way, however an
    other official namespace from Net)

    :-)

    I hope this helps,

    Cor


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: CType

      "Todd Plambeck" <tplam@nospamfl ash.net> schrieb:[color=blue]
      > Is there a more C# like alternative to CType? I don't like using the
      > VB6esque "C" conversion methods(CStr, CInt, etc) . I'd prefer to user
      > something like Convert.ToInt32 (), but can't find a equivalent for
      > converting objects.[/color]

      If you are looking for cast operators, 'DirectCast' and 'CType' are the way
      to go. There is absolutely no reason for not using the 'C*'
      conversions/casts.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Todd Plambeck

        #4
        Re: CType

        Thanks guys! CType it is. I have read that Convert.To... is more
        efficient/faster then the C* methods. I know, I know the fractions of
        milliseconds won't make much difference, but you gotta get it anywhere you
        can.

        Thanks again.

        Todd

        "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
        news:%23PHo1Q%2 3gFHA.1252@TK2M SFTNGP09.phx.gb l...[color=blue]
        > "Todd Plambeck" <tplam@nospamfl ash.net> schrieb:[color=green]
        >> Is there a more C# like alternative to CType? I don't like using the
        >> VB6esque "C" conversion methods(CStr, CInt, etc) . I'd prefer to user
        >> something like Convert.ToInt32 (), but can't find a equivalent for
        >> converting objects.[/color]
        >
        > If you are looking for cast operators, 'DirectCast' and 'CType' are the
        > way to go. There is absolutely no reason for not using the 'C*'
        > conversions/casts.
        >
        > --
        > M S Herfried K. Wagner
        > M V P <URL:http://dotnet.mvps.org/>
        > V B <URL:http://classicvb.org/petition/>[/color]


        Comment

        • Jay B. Harlow [MVP - Outlook]

          #5
          Re: CType

          Todd,
          I've read the opposite that the C* methods are more efficient/faster then
          the Convert.To* methods.




          Hope this helps
          Jay


          "Todd Plambeck" <tplam@nospamfl ash.net> wrote in message
          news:ecTGsWChFH A.3312@TK2MSFTN GP10.phx.gbl...
          | Thanks guys! CType it is. I have read that Convert.To... is more
          | efficient/faster then the C* methods. I know, I know the fractions of
          | milliseconds won't make much difference, but you gotta get it anywhere you
          | can.
          |
          | Thanks again.
          |
          | Todd
          |
          | "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
          | news:%23PHo1Q%2 3gFHA.1252@TK2M SFTNGP09.phx.gb l...
          | > "Todd Plambeck" <tplam@nospamfl ash.net> schrieb:
          | >> Is there a more C# like alternative to CType? I don't like using the
          | >> VB6esque "C" conversion methods(CStr, CInt, etc) . I'd prefer to user
          | >> something like Convert.ToInt32 (), but can't find a equivalent for
          | >> converting objects.
          | >
          | > If you are looking for cast operators, 'DirectCast' and 'CType' are the
          | > way to go. There is absolutely no reason for not using the 'C*'
          | > conversions/casts.
          | >
          | > --
          | > M S Herfried K. Wagner
          | > M V P <URL:http://dotnet.mvps.org/>
          | > V B <URL:http://classicvb.org/petition/>
          |
          |


          Comment

          Working...