Why Static keyword before the function signature [duplicate]
Possible Duplicate:
Why must C# operator overloads be static?
Why Static keyword before the function signature of all the overload开发者_运维知识库ed 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?
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.)
Otherwise you would Always need an instance of the Object to perform that. Which you might not have on case a or b is null.
精彩评论