123.ToString(); Text = (123 + 456).ToString(); 不光是整数是对象,类本身也是对象object o = typeof(TextBox); Text = o.ToString();要相信自己测试的结果
在未装箱的情况下,值类型不继承任何类型,装箱的情况下值类型才会继承ValueType或者Enum,并实现其它接口 [原文:In their unboxed form value types do not inherit from any type. Boxed value types shall inherit directly from System.ValueType unless they are enumerations, in which case, they shall inherit from System.Enum. Boxed value types shall be sealed. 摘自:Common Language Infrastructure(CLI) Partition I: Concepts and Architecture Final Draft, Apr 2005 第42页]
int是基本数据类型,但它继承自object类型,当然就有ToString()方法了 解释的不错
LZ是不是学习其他语言学惯了,语法会用就行 深究的话 你知道也没用 细节以后会慢慢体会到
你会汇编的话 可以看看CLI语言 那你就会语法所有的细节了
c#所有都继承自object
object有3个虚方法Equals,GetHashCode,ToString。1个方法GetType。2个静态方法Equals,ReferenceEquals这些是所有数据类型都有的。也就是说任何数据类型都有ToString()
LZ是不是学习其他语言学惯了,语法会用就行 深究的话 你知道也没用 细节以后会慢慢体会到
你会汇编的话 可以看看CLI语言 那你就会语法所有的细节了
--------------------------------------
正解
Text = (123 + 456).ToString();
不光是整数是对象,类本身也是对象object o = typeof(TextBox);
Text = o.ToString();要相信自己测试的结果
[原文:In their unboxed form value types do not inherit from any type. Boxed value types shall inherit directly from System.ValueType unless they are enumerations, in which case, they shall inherit from System.Enum. Boxed value types shall be sealed.
摘自:Common Language Infrastructure(CLI) Partition I: Concepts and Architecture Final Draft, Apr 2005 第42页]
c#所有都继承自object