Is it possible to overload operators in VB.net


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Is it possible to overload operators in VB.net

  1. #1
    Siva Guest

    Is it possible to overload operators in VB.net



    I have two doubts in vb.net. First, Can we overload operators in vb.net ?
    Second, In C/C++ we have "typedef" using which we can define datatypes to
    avoid datatype mismatch. Is there anything like this in vb.net . Please reply
    as soon as possible.


  2. #2
    David A. Rothgery Guest

    Re: Is it possible to overload operators in VB.net

    Siva <sivaraja.thambi@ssitechnologies.com> wrote:
    >
    >
    > I have two doubts in vb.net. First, Can we overload operators in vb.net ?
    > Second, In C/C++ we have "typedef" using which we can define datatypes to
    > avoid datatype mismatch. Is there anything like this in vb.net . Please reply
    > as soon as possible.


    VB.NET, like Java, does not allow operator overloading. C# does, though
    C# operator overloading is more restrictive than C++ operator
    overloading (this is generally regarded as a good thing).

    typedef still exists in C/C++ largely for backward compatibility; at one
    time it was the only way to name a user-defined type in C. So typedef,
    like #DEFINE, is something that newer general-purpose languages like
    Java, C#, and VB.NET have left out.

    --
    Dave Rothgery
    Picking nits since 1976
    drothgery@alum.wpi.edu
    http://drothgery.editthispage.com

  3. #3
    Mattias Sjögren Guest

    Re: Is it possible to overload operators in VB.net

    David,

    >So typedef,
    >like #DEFINE, is something that newer general-purpose languages like
    >Java, C#, and VB.NET have left out.


    using in C# and Imports in VB.NET can be used in a way very similar to
    typedef, so I don't agree with that.


    Mattias

    ===
    Mattias Sjögren (VB MVP)
    mattias @ mvps.org
    http://www.msjogren.net/dotnet/

  4. #4
    Siva Guest

    Re: Is it possible to overload operators in VB.net


    Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote:
    >David,
    >
    >>So typedef,
    >>like #DEFINE, is something that newer general-purpose languages like
    >>Java, C#, and VB.NET have left out.

    >
    >using in C# and Imports in VB.NET can be used in a way very similar to
    >typedef, so I don't agree with that.
    >
    >
    >Mattias


    In C/C++ I can say
    "typedef long Amount" and I can use "Amount" as the datatype instead of giving
    "long" in all the source files in a big project, this way we can avoid datatype
    mismatch. Even in future if there is a need to change the datatype of Amount
    from long to short its a change in one place only. If we use "long" instead
    of "Amount" we will have to change all the sources. How to achieve this in
    VB.net ?? Please help me.



  5. #5
    Tom Shelton Guest

    Re: Is it possible to overload operators in VB.net

    Imports Amount = System.Int32

    Public Class Form1
    Inherits Form

    Private Cost As Amount = 0

    ....

    End Form

    HTH,
    Tom Shelton

    "Siva" <sivaraja.thambi@ssitechnologies.com> wrote in message
    news:3d4a38f4$1@10.1.10.29...
    >
    > Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote:
    > >David,
    > >
    > >>So typedef,
    > >>like #DEFINE, is something that newer general-purpose languages like
    > >>Java, C#, and VB.NET have left out.

    > >
    > >using in C# and Imports in VB.NET can be used in a way very similar to
    > >typedef, so I don't agree with that.
    > >
    > >
    > >Mattias

    >
    > In C/C++ I can say
    > "typedef long Amount" and I can use "Amount" as the datatype instead of

    giving
    > "long" in all the source files in a big project, this way we can avoid

    datatype
    > mismatch. Even in future if there is a need to change the datatype of

    Amount
    > from long to short its a change in one place only. If we use "long"

    instead
    > of "Amount" we will have to change all the sources. How to achieve this in
    > VB.net ?? Please help me.
    >
    >




  6. #6
    Tim Overbay Guest

    Re: Is it possible to overload operators in VB.net

    My gosh! I never realized you could do that with Imports! Very cool.

    Tim

    "Tom Shelton" <tom@mtogden.com> wrote in message news:3d4a5d6c@10.1.10.29...
    > Imports Amount = System.Int32
    >
    > Public Class Form1
    > Inherits Form
    >
    > Private Cost As Amount = 0
    >
    > ....
    >
    > End Form
    >
    > HTH,
    > Tom Shelton
    >
    > "Siva" <sivaraja.thambi@ssitechnologies.com> wrote in message
    > news:3d4a38f4$1@10.1.10.29...
    > >
    > > Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote:
    > > >David,
    > > >
    > > >>So typedef,
    > > >>like #DEFINE, is something that newer general-purpose languages like
    > > >>Java, C#, and VB.NET have left out.
    > > >
    > > >using in C# and Imports in VB.NET can be used in a way very similar to
    > > >typedef, so I don't agree with that.
    > > >
    > > >
    > > >Mattias

    > >
    > > In C/C++ I can say
    > > "typedef long Amount" and I can use "Amount" as the datatype instead of

    > giving
    > > "long" in all the source files in a big project, this way we can avoid

    > datatype
    > > mismatch. Even in future if there is a need to change the datatype of

    > Amount
    > > from long to short its a change in one place only. If we use "long"

    > instead
    > > of "Amount" we will have to change all the sources. How to achieve this

    in
    > > VB.net ?? Please help me.
    > >
    > >

    >
    >




  7. #7
    Siva Guest

    Re: Is it possible to overload operators in VB.net


    Hi ,

    Thanks for the help. One more doubt in the same line, If we create alias
    using Imports,like "Amount" , the scope of the Amount is the file in which
    it is declared. We cant refer Amount from other files.But I want to declare
    all aliases in a single file and use it in all the files in the project.
    Any idea ?

    Siva.

    "Tom Shelton" <tom@mtogden.com> wrote:
    >Imports Amount = System.Int32
    >
    >Public Class Form1
    > Inherits Form
    >
    > Private Cost As Amount = 0
    >
    > ....
    >
    >End Form
    >
    >HTH,
    >Tom Shelton
    >
    >"Siva" <sivaraja.thambi@ssitechnologies.com> wrote in message
    >news:3d4a38f4$1@10.1.10.29...
    >>
    >> Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote:
    >> >David,
    >> >
    >> >>So typedef,
    >> >>like #DEFINE, is something that newer general-purpose languages like
    >> >>Java, C#, and VB.NET have left out.
    >> >
    >> >using in C# and Imports in VB.NET can be used in a way very similar to
    >> >typedef, so I don't agree with that.
    >> >
    >> >
    >> >Mattias

    >>
    >> In C/C++ I can say
    >> "typedef long Amount" and I can use "Amount" as the datatype instead of

    >giving
    >> "long" in all the source files in a big project, this way we can avoid

    >datatype
    >> mismatch. Even in future if there is a need to change the datatype of

    >Amount
    >> from long to short its a change in one place only. If we use "long"

    >instead
    >> of "Amount" we will have to change all the sources. How to achieve this

    in
    >> VB.net ?? Please help me.
    >>
    >>

    >
    >



  8. #8
    Kunle Odutola Guest

    Re: Is it possible to overload operators in VB.net


    "Siva" <sivaraja.thambi@ssiworldwide.com> wrote in message
    news:3d4f6422$1@10.1.10.29...
    >
    > Hi ,
    >
    > Thanks for the help. One more doubt in the same line, If we create alias
    > using Imports,like "Amount" , the scope of the Amount is the file in which
    > it is declared. We cant refer Amount from other files.But I want to

    declare
    > all aliases in a single file and use it in all the files in the project.
    > Any idea ?


    You can't (and shouldn't want to). If you really want the class to be called
    Amount, well call it Amount then.....

    Kunle



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center