Understanding Operator Overloading in C#
page 2 of 5
by Joydip Kanjilal
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 30965/ 52

Introducing Operator Overloading

Whenever you overload an operator in C#, you have specific operator methods created that are related to the operator that you overload. Hence, when you overload the + operator, the overloaded operator method name is operator+. Note that all the overloaded operator methods are named "operator."  Further, all operator methods in C# are static. To know more on static and non-static methods, refer to my post at my blog at the link given below.

Static vs Non - Static Methods

Note that operator overloading is a feature of the C# language, not of the IL. Visual Basic .NET does not support operator overloading. Hence, if you were to access C# methods from non C# languages, ensure that you provide some methods that act as a wrapper on your operator methods to facilitate compliancy. If you have overloaded the + operator in your C# class, ensure that you have a method (something like Add or AddValues) that would acts as a wrapper around your operator+ method so as to enable the same to be accessed from outside.

I would not like to drill down into what are the operators that can be overloaded in C# and those that cannot be overloaded or the associated rules. There is plenty of stuff on it. You can find some of them at the following links.

Operator Overloading In C#

Overloading Operators


View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-02-25 3:31:58 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search