The compiler generated one (the overloaded operator) needs to be one that isn't likely to collide with names that a user would choose. Choosing "Add" for this would be a bad idea.
I do agree that if the operator is static, you'd probably want nicely named version to also be static. -----Original Message----- From: Jon Jagger [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 29, 2002 8:39 AM To: [EMAIL PROTECTED] Subject: Re: [DOTNET] Operators, CLS compliance, friendly partner methods On Wed, 29 May 2002 09:29:11 -0500, Tomas Restrepo <[EMAIL PROTECTED]> wrote: >Jon, > > >> In his excellent book Jeffrey Richter says the Microsoft guidelines >> recommend operators are accompanied by a friendly public instance >> method that calls the operator method internally. For example the >> suggested CLS compliant name for operator + is Add. Does anyone >> know... >> >> /1/ why the friendly method should be an instance method rather than >> a static method? > >I imagine because it's somewhat "simpler" and more natural to use? But is it? An instance method has a natural asymmetry. The this operand is treated differently to an argument for example. With a static method there is no asymmetry. An instance method also suggests virtualness which I am not convinced is a happy bedfellow of an operator. I think perhaps a static method matches an operator better. Opinions? >> /2/ why the C# compiler generates a static method called op_Addition >> for >> operator+ rather than the recommended instance method called Add? > >Because that's the operator itself. IOW, Managed operators are nothing more >than static methods with a known name and marked with the specialname >metadata attribute in the signature. Yes. But why is it called op_Addition and not Add. Or to put it another way, why is there a need for op_Addition _and_ Add? Couldn't the operator be translated into a method with the recommended friendly name? Cheers JJ You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.