本文介绍了值类型充当对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即使值类型通常表示简单的值,但它们仍然充当对象.
实际上,我们可以在它们上调用方法,如下所示
int a = 10;
字符串s = a.ToString();
为什么会这样?
Even though value types often represent simple values, they still function as objects.
Infact we can call methods on them, as below
int a = 10;
string s = a.ToString();
why so?
How a value type is working as an Object?
推荐答案
public class someClass
{
public int someInt;
public string someString;
}
当您创建新的"someClass"实例时:"someInt设置为#0,而" someString设置为"null:它们立即可用".
When you create a new instance of ''someClass: ''someInt is set to #0, and ''someString is set to ''null : they are immediately ''usable.''
这篇关于值类型充当对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!