Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
why we use public static keyword with operator overloading can it is possible that we not use these keywords?
Posted
Updated 28-Oct-11 0:56am
v2

It was a C# design decision, see Eric Lippert's "Why are overloaded operators always static in C#?" for some insight.
 
Share this answer
 
See the description here[^].
 
Share this answer
 
Simply because an operator overload does not reference a class: it takes parameters and returns a value, but it does not have access to the this object or any non static members of the class.
If you write a overload for the logical not operator '!' then it takes a single parameter - the class instance to perform the operation on.

It is a static method, so it needs the static keyword.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900