I am wondering why the following is marked as an error with no suitable method found to override in VS2010 (.NET 4):
public override string ToString(int foo=0) {
// some stuff
}
I’ve found this which seems somewhat similar (at least also surprising behavior with optional parameters), but I don’t understand why this method does not override ToString().
Now I’m obviously aware how to easily fix this problem by overloading ToString, so I’m not interested in solutions for the problem, but in the rationale behind this limitation.
It simply doesn’t have the same signature. Overriding methods are limited to strictly the same signature as the method that they are overriding, and optional parameters aren’t just syntactic sugar for overloading; they’re also part of the method signature and even part of the resultant IL code.
This:
Is not the same as this:
No matter how you slice it. So, error.