How to: Custom Implicit/Explicit conversion in VB.NET 2003

Hai .....,
         I would like to define some custom Implicit conversion function within my VB class. How can i do that. I have seen samples in C# but not in VB. Can anyone please help me on this


Answer this question

How to: Custom Implicit/Explicit conversion in VB.NET 2003

  • twostepted

    a few methods to check out:

    DirectCast
    Ctype
    Convert

  • Lord_Anubis

    Hemant,
    Jay provided you with this link as a resource:

    http://msdn2.microsoft.com/library/yf7b9sy7(en-us,vs.80).aspx

  • Donna M. Singel

    VB 2003 does *not* support defining implicit or explicit conversion operators on a class. You can use the operators on a class defined in C# by calling the op_implicit & op_explicit shared routines that C# creates.

    VB 2005 *does* support defining & using implicit & explicit conversion operators on a class.

    For details see:

    http://msdn2.microsoft.com/library/yf7b9sy7(en-us,vs.80).aspx

    Jay

  • Kevin LZJ

    Since VB does not have the implicit, operator, or digit keywords/type ...this is a close translation of the above code:



    Public Shared Function ImplicitConverter(ByVal d As Char) As Byte

    Console.WriteLine("conversion occurred")

    Return Convert.ToByte(d)

    End Function


     







  • jcviera

    No DMan1,
                You missed me Smile. For example, consider the conversion listing below in C#:


       public static implicit operator byte(Digit d)
       {
          Console.WriteLine( "conversion occurred" );
          return d.value;
       }

     


                Can you provide me the translated version in VB.NET. Yes i want this Big Smile


  • Dave Waterworth

     You can use the operators on a class defined in C# by calling the op_implicit & op_explicit shared routines that C# creates.

    Hai Jay,
              How can I do that A sample can be really helpful or a link to such a resource Big Smile

  • How to: Custom Implicit/Explicit conversion in VB.NET 2003