This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
= Operator (Visual Basic)
- 12 contributors
Assigns a value to a variable or property.
variableorproperty Any writable variable or any property.
value Any literal, constant, or expression.
The element on the left side of the equal sign ( = ) can be a simple scalar variable, a property, or an element of an array. The variable or property cannot be ReadOnly . The = operator assigns the value on its right to the variable or property on its left.
The = operator is also used as a comparison operator. For details, see Comparison Operators .
Overloading
The = operator can be overloaded only as a relational comparison operator, not as an assignment operator. For more information, see Operator Procedures .
The following example demonstrates the assignment operator. The value on the right is assigned to the variable on the left.
- &= Operator
- *= Operator
- += Operator
- -= Operator (Visual Basic)
- /= Operator (Visual Basic)
- \= Operator
- ^= Operator
- Comparison Operators
- Local Type Inference
Additional resources
- Mark Forums Read
- View Site Leaders
- What's New?
- Advanced Search
Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.
- »
- VISUAL BASIC 10
Operator Overloading in VB.NET
In this article we will see the operator overloading in Visual Basic.net.
When an operator can perform more than one operations, specially with objects, known as operator overloading.A function name can be replaced with the operator using operator keyword.
Important points related to Operator Overloading or guidelines:
- Don't change an operator's semantic meaning. The result of an operator should be intuitive.
- Make certain overloaded operators are shared methods.
- You cannot overload assignment e.g., the "=" operator .
VB.NET allows the following operators to be overloaded:
- + (increment/plus - unary and binary)>
- - (decrement/minus - unary and binary)
- Not (unary)
- * (multiply - binary)
- / (divide - binary)
- \ (integer divide - binary)
- & (concatenate - binary)
- Like (binary)
- Mod (binary)
- And (binary)
- Or (binary)
- ^ (raise to power - binary)
- << (left shift - binary)
- >> (right shift - binary)
- = (equals - binary)
- <> (not equals - binary)
- < (less than - binary)
- > (greater than - binary)
- <= (less than or equal to - binary)
- >= (greater than or equal to - binary)
This example shows the (+) Operator Overloading in VB.NET:
Module module1
Class Size
Private feet As Integer , inch As Integer
Public Sub New ( ByVal f As Integer , ByVal i As Integer )
feet = f
inch = i
End Sub
Public Sub ShowSize()
Console .WriteLine( "Size is {0} feet and {1} inch" , feet, inch)
Public Shared Function Add( ByVal x As Size , ByVal y As Size ) As Size 'add method
Dim f As Integer = x.feet + y.feet
Dim i As Integer = x.inch + y.inch
If i >= 12 Then
i = i - 12
f += 1
End If
Return New Size (f, i)
End Function
Public Shared Operator +( ByVal x As Size , ByVal y As Size ) As Size ' add method replace with operator(+) using operator keyword
End Operator
Public Shared Sub Main()
Dim s1 As New Size (5, 9)
Dim s2 As New Size (8, 8)
Dim s3 As Size = Size .Add(s1, s2) ' add method perform the task
'Dim s3 As Size = s1 +s2 ' + operator perform the task
End Class
OUTPUT :
In the above example (+) operator perform more than one operation. the function name add replace with the operator using Operator keyword .
Related Articles
- How to Method Overloading in VB.NET
- VB.NET Overloading
- WPF Grid Using VB.NET
- Operators in Visual Basic .NET
- Concat and Cast operator Linq in VB.NET
- Distinct and ElementAt operator in Linq using VB.NET
- Polymorphism in VB.NET
- Polymorphism in Visual Basic .NET
- LINQ FirstOrDefault and LastOrDefault operator in VB.NET
- Introduction of DataGrid Control in VB.NET
- ACTIVE DIRECTOTRY IN VB.NET
- ALGORITHMS AND VB.NET
- ARRAY IN VB.NET
- ASP.NET AJAX IN VB.NET
- ASP.NET USING VB.NET
- ASSEMBLIES IN VB.NET
- COM INTEROP IN VB.NET
- CRYPTOGRAPHY IN VB.NET
- CRYSTAL REPORTS IN VB.NET
- DATABASE & DBA
- DEPLOYMENT IN VB.NET
- DESIGN & ARCHITECTURE
- DIRECTX WITH VB.NET
- ENTERPRISE DEVELOPMENT
- FILE IN VB.NET
- GAMES IN VB.NET
- GDI+ IN VB.NET
- LINQ WITH VB.NET
- MOBILE DEV IN VB.NET
- MULTITHREADING IN VB.NET
- NETWORKIN WITH VB.NET
- OFFICE AND VB.NET
- PRINTING IN VB.NET
- REMOTING IN VB.NET
- REPORTS IN VB.NET
- SECURITY IN VB.NET
- SILVERLIGHT USING VB.NET
- Speech in VB.NET
- STRING IN VB.NET
- VB.NET ADO.NET
- VB.NET ARTICLE
- VB.NET EXCEPTION HANDLING
- VB.NET HOW DO I
- VB.NET LANGUAGE
- VB.NET TUTORIALS
- VB.NET WINDOWS SERVICES
- VISUAL BASIC LANGUAGE
- WCF WITH VB.NET
- WEB CONTROL IN VB.NET
- WEB DEV IN VB.NET
- WEB FORM WITH VB.NET
- WEB SERVICES IN VB.NET
- WINDOWS CONTROLS
- WINDOWS FORMS IN VB.NET
- WORKFLOW IN VB.NET
- WPF IN VB.NET
- XAML IN VB.NET
- XML IN VB.NET
More Articles
- Setup for a Windows Forms application using Visual Studio 2010 in VB.NET
- How to Check Installed .NET Versions on Hosting Server in VB.NET
- TabControl in a Windows Forms application in Visual Studio 2010 in VB.NET
- Xml database in Windows Forms application using Visual Studio 2010 in VB.NET
- Date and Time in Window Application in VB.NET
- ListBox Behavior in VB.NET
- Use of ThreeState property with CheckBox in VB.NET
- Difference Between Interface And Abstract Class in VB.NET
- Type Conversion in Calculation in VB.NET
- String class in VB.NET- String.Compare method
- Enumertors in VB.NET
- How to use IDisposable interface in VB.NET
- Structure in VB.NET
- ICloneable interface in VB.NET
- Overriding in VB.NET
- Use Indexer in VB.NET
- How to change the Console display in VB.NET
- Reflection in VB.NET
- Method Parameter Types in VB.NET
- How to Sort and Reverse of Array in VB.NET
- Pass by Value and Pass by Reference in VB.NET
- Use of IndexOf-Array in VB.NET
- Authentication and Code Groups in VB.NET
- Collections in VB.NET
- Use of LowerBound and UpperBound with Array in VB.NET
- Interface in VB.NET
- Use of CreateInstance method to construct an array in VB.NET
- HelpProvider control in VB.NET
- How to Clone an Array in VB.NET
- Registry.GetValue in VB.NET
- Use the Err.Number in VB.NET
- How to use Activator in VB.NET
- Use of RegistryKeys in VB.NET
- Use ControlChars.Lf in VB.NET
- Visual Studio 2010 ErrorProvider control in VB.NET
- Use of Registry.SetValue in VB.NET
- Visual Studio 2010 CheckBox control in VB.NET
- Use of Registry.CurrentUser in VB.NET
- Ajax application with jscript file in VB.NET
- Data Encryption in VB.NET using DES
- Visual Studio 2010 ComboBox control in VB.NET
- Working with AJAX Control in ASP.NET using VB.NET
- Visual Studio 2010 Progress Bar control in VB.NET
- Hashtable in VB.NET
- Visual Studio 2010 Tooltip control in VB.NET
- Use of IsNothing() function in VB.NET
- Visual Studio 2010 Rich Textbox control in VB.NET
- Use of IsDate() function in VB.NET
- Enable JavaScript in VB.NET
- TERMS & CONDITIONS
- REPORT ABUSE
IMAGES
VIDEO