什么是背后的对象类型有类似的ToString(),GetHash code()的GetType等方法的原因类似、对象、原因、类型

由网友(颜值界一哥)分享简介:我有一个看起来很傻的问题。有没有像背后ToStrin(),GetHash code()的GetType()等方法确定的基本对象类型的任何具体原因。难道这些方法在内部使用由.NET Framework为任何目的。只是想知道,一直这样的设计背后的想法。I have a question which might look...

我有一个看起来很傻的问题。有没有像背后ToStrin(),GetHash code()的GetType()等方法确定的基本对象类型的任何具体原因。难道这些方法在内部使用由.NET Framework为任何目的。只是想知道,一直这样的设计背后的想法。

I have a question which might look silly. Is there any specific reason behind defining methods like ToStrin(),GetHashCode(),GetType() etc on the base Object Type . Are these methods internally be used by the .Net framework for any purpose. Just curious to know the thoughts that have been behind this design.

谢谢, sveerap

Thanks, sveerap

推荐答案

这些方法被认为是所有对象所需的最低限度。通过向他们介绍了 System.Object的类,它们可在.NET中的所有对象。

These methods were considered the bare minimum required by all objects. By introducing them to the System.Object class, they are available on all objects within .NET.

每个服务的目的:

等于的ReferenceEquals 用于相等检查 在散列集合中使用 GetHash code 允许对象 的GetType 需要反思工作 的ToString 允许所有对象,psented以字符串形式不论类型,需重新$ P $,这是非常有用 的Finalize 使资源得到妥善的垃圾收集处理 MemberwiseClone 允许对象的浅副本生成 Equals and ReferenceEquals are used for equality checking GetHashCode allows objects to be used in hashed collections GetType is required for reflection to work ToString allows all objects, regardless of type, to be represented in a string form, which is incredibly useful Finalize allows resources to be handled properly by the garbage collector MemberwiseClone allows for shallow copies of objects to be generated
阅读全文

相关推荐

最新文章