加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 由于Int32是一个值类型,为什么它继承.ToString()?

发布时间:2020-12-15 06:54:02 所属栏目:百科 来源:网络整理
导读:These are the docs关于.ToString()提示了这个问题.他们说: Because Object is the base class of all reference types in the .NET Framework,this behavior [.ToString()] is inherited by reference types that do not override the ToString method. 更
These are the docs关于.ToString()提示了这个问题.他们说:

Because Object is the base class of all reference types in the .NET
Framework,this behavior [.ToString()] is inherited by reference types that do not
override the ToString method.

更进一步的说:

For example,the base types such as Char,Int32,and String provide ToString implementations

但Int32是一个结构体,因此必须是一个值类型.

那么这里发生了什么? Int32实现它是非常自己的.ToString()与Object无关?

解决方法

Int32是一个结构体,因此是一个值类型.
但:
System.Object
   System.ValueType
      System.Int32

Int32派生自System.ValueType,它本身来源于System.Object. Etvoilà…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读