Although you do not need to write overloaded operators every day, this feature certainly puts the latest version of VB.NET (whether you call it 2.0 or 8.0—there is some confusion in this area) on par with even the most powerful object-oriented languages. This article demonstrates a step-by-step process for writing custom operators, including a brief explanation for neophytes. Of course, if you didn't like VB.NET because of its differences from VB6, you probably won't get too excited about the ability to overload operators in VB.NET 2.0.


What Operators Are and Why You Overload Them


Programming has a rich history based in mathematics. Mathematics is steeped in meaningful symbols, operators, and operands. Operators are symbols that perform a function and operands are the things on which operators operate.


Operators typically indicate how many operands they use. Usually, you'll encounter unary, binary, and ternary operators. Unary means one operand, binary means two, and ternary means three. "Not" is an example of a unary operator; "+" is an example of a binary operator; and "?:" is an example of a ternary operator. (I have never seen a quaternary operator.)


Operators are convenient because they are quick to write and they are familiar, especially in arithmetic operations. For example, "&" and "+" are Boolean and arithmetic operators, but you can also used them to perform string concatenation for string operands. Clearly, operators have had multiple—or overloaded—meanings for some time. A natural evolution is this ability extending to us programmers.


Read | DevGuru


 
Comments are closed.