为什么在System.Object中定义的MemberwiseClone受保护? [英] Why is MemberwiseClone defined in System.Object protected?

查看:105
本文介绍了为什么在System.Object中定义的MemberwiseClone受保护?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么MemberwiseClone被定义为受保护的。这意味着只有派生类型才能访问它。

I'm wondering why MemberwiseClone is defined as protected. This means that only derived types can access it. What is the problem if it was defined as public?

推荐答案


  • 很多事情没道理被克隆;与非托管句柄相关的任何内容,例如

  • 大多数对象不需要克隆工具

  • 深度复制如果您不涉及一些简单的案例,那么适当的事情真的很难

  • 在许多情况下,比起盲人克隆,隐喻更好

  • 向需要它的类型中手动添加克隆工具 非常简单

    • A lot of things don't make sense to be cloned; anything that talks to an unmanaged handle, for example
    • Most objects do not need a clone facility
    • Deep-copying something properly is really hard if you go outside of a few simple cases
    • In many cases, there are better metaphors than blind clones
    • Manually adding a clone facility to your types that need it is trivially easy
    • 那么,对我来说,默认情况下应该 将其添加到公共API中是很容易的事。

      To me, then, it is a no-brainer that this should not be added to the public API by default.

      这篇关于为什么在System.Object中定义的MemberwiseClone受保护?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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