如何使方法不可用 [英] how to make a method as not available

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

问题描述

嗨常见,



正常方法我们不能宣称为密封方法。



只有过度或者只有我们可以制作密封的方法。



但我们如何做正常方法密封。



提前谢谢。

Hi frends,

normal method we can not declared as sealed method.

only overdide or overridable only we can make as sealed method.

but how we do normal method as sealed.

Thanks in advance.

推荐答案

你根本无法密封C#中的方法 - 你使用密封用类来阻止它们被扩展或继承。



如果你不希望你班外的代码能够在其中调用方法,只需将其声明为 private (或 protected ,如果您希望派生类能够访问它)
You can't "seal" a method in C# at all - you use sealed with classes to stop them being extended or being inherited from.

If you don't want code outside your class to be able to call a method within it, just declare it as private (or protected if you want derived classes to be able to access it)


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

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