Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Static keyword before the function signature [duplicate]

Tags:

c#

Possible Duplicate:
Why must C# operator overloads be static?

Why Static keyword before the function signature of all the overloaded operators in C# like:

public static void operator = (Object a, Object b)

When we are doing a = b; then a value will be implicitly passed right. So there is no need of static keyword. It must be like:

public void operator = (Object b)

Is it?

like image 507
Sunil Avatar asked Feb 23 '10 10:02

Sunil


1 Answers

The fact that operators are static allows them to be used in situations where there are null values. It also emphasizes the fact that operators are not applied polymorphically. (They potentially could be applied polymorphically if they weren't static, admittedly... but overriding would generally be a bad idea anyway IMO.)

(Note that you can't overload the assignment operator in C# anyway.)

like image 153
Jon Skeet Avatar answered Oct 22 '22 07:10

Jon Skeet