Q) why ‘public’ & ‘static’ is necessary in operator overloading in C#?
tried this article
But could someone explain what the author is trying to say?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The author makes a simple cost/benefit analysis of a potential feature of operator overloading in a non-static way, and concludes that the benefits do not justify the costs: you can easily mimic the functionality of instance overloading of operators by dispatching to a virtual method from inside of a statically overloaded operator. However, the costs of letting you define overloaded operators without an intermediate virtual functions are great:
2+cmay be illegal whilec+2is OK)nullreferences on the left-hand sideAt the end, the author notes that rather than introducing a feature that introduces much confusion without a significant benefit, they went for a cleaner design that can be extended to provide comparable levels of functionality.