如何防止方法重载 [英] How to prevent method overloading

查看:86
本文介绍了如何防止方法重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我不知道这个问题是对还是错,但我只是被问到如何防止c#中的超载。关于这个的任何想法?

Hello ,

I dont know whether this question is right or wrong, but i was just asked that how can i prevent overloading in c#. Any ideas on this?

推荐答案

除了 Sergey Alexandrovich Kryukov [ ^ ],我建议阅读: CA1402:避免COM中的重载可见界面 [ ^ ] 。这可能有助于你理解谢尔盖想要告诉你什么。



简而言之:你必须回到基础并阅读继承 [ ^ ], polimorphism [ ^ ],成员超载 [ ^ ]等。
In addition to solution 1 by Sergey Alexandrovich Kryukov[^], i'd suggest to read this: CA1402: Avoid overloads in COM visible interfaces[^]. It might help you to understand what Sergey wanted to tell you.

In a short: you have to go back to basics and read about inheritance[^], polimorphism[^], member overloading[^], etc.


你不能通过一个简单的原因来阻止超载:没有什么可以防止。它不是一种机制或任何特殊的东西,它只是命名规则:您可以为不同的方法使用相同的名称,前提是可以解决由参数集调用的方法。如果允许某个名字,你就不能禁止它。



(也许你搞砸了术语,意思是说防止覆盖。然后,在上课,你可以用密封。)



-SA
You cannot prevent "overloading" by one simple reason: there is nothing to "prevent". It's not a mechanism or anything special, it's just the rule for naming: you can use the same names for different methods provided that it's possible to resolve which method is to be called by the set of parameters. If some name is allowed, you cannot make it prohibited.

(Perhaps you messed up the terminology and meant to say "prevent overriding". Then, on the level of class, you could use sealed.)

—SA


这篇关于如何防止方法重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆