C# documentation Compiler Error CS0750 states:
A partial method cannot have access modifiers or the virtual, abstract, override, new, sealed, or extern modifiers.
Which is completely untrue since the signature of a partial method can be defined with an access modifier(s), or the virtual
, override
, new
, sealed
, or extern
modifier. And no compile time error will be generated as long as the implementation part of the partial method is also provided. The abstract
modifier is the exception (that part of the statement is correct).
But why does the documentation states otherwise? Is the information in that documentation incorrect?
CodePudding user response:
This documentation could be outdated or the error cannot happen any more.
The possibility to use a partial method declaration with one of these keywords to implement it elsewhere is - as far as I can tell - rather new. I early versions of C#, only the special case with a partial method that was (optionally) not implemented was allowed. If you read the documentation on partial methods the sentence
A partial method isn't required to have an implementation in the following cases:
preceedes the limitations that CS0750 would report.
In fact, if I declare a partial method with virtual
, and don't implement it, I get a new error CS8795. I therefore suspect that it's not even possible to get CS0750 any more. I would be interested to see sample code that generates CS0750 with a recent compiler.