什么是对象关键字 [英] what is object keyword

查看:108
本文介绍了什么是对象关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C Sharp中什么是对象关键字?

What is object keyword in c sharp?

推荐答案

来自MSDN(
From MSDN (http://msdn.microsoft.com/en-us/library/9kkx3h3c.aspx[^]):

The object type is an alias for Object in the .NET Framework. In the unified type system of C#, all types, predefined and user-defined, reference types and value types, inherit directly or indirectly from Object. You can assign values of any type to variables of type object. When a variable of a value type is converted to object, it is said to be boxed. When a variable of type object is converted to a value type, it is said to be unboxed. For more information, see Boxing and Unboxing.

And the definition of Object:
Supports all classes in the .NET Framework class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all classes in the .NET Framework; it is the root of the type hierarchy.


我认为这是一种生动展示.NET中的对象的有趣方法:在.NET中的VisualStudio中:放置一些内容像这样在某个地方的代码中,设置一个断点,然后编译并运行,然后检查值:
I think this an interesting way to make vivid what object/Object in .NET is: in VisualStudio in .NET: put something like this in code somewhere, set a breakpoint, then compile and run, and examine the values:
bool intValue = 32 is object;
bool stringValue = "hello" is object;

,请注意,Intellisense将在等号运算符的右侧弹​​出一个预编译消息,该表达式为永远是真的.

问问自己:如果每个.NET类型都是一个对象,则必须为真?

哎呀:我是否说过每个人",然后问自己

And notice that Intellisense will give you a pre-compile message pop-up over the right side of the equal operator that this expression is always true.

Ask yourself: what must be true if every .NET Type is-a object ?

Whoops: did I say ''every:'' then ask yourself what it means that

bool nullValue = null is object; // => false

是什么意思,所以,"null"不是对象!

您想了解一下:可为空的类型呢?您认为会发生什么:

So, ''null'' is not an object !

You want to get fancy: what about nullable types ? What do you think happens:

int? myNullInt = null; // compare with setting myNullInt = 32;

bool nullableType = myNullInt is object;

如果您想了解哲学,也许可以用Pascal解释一下,然后说:.NET中的对象/对象是那种类型,其中心无处不在,圆周无处." "nowhere"等于null:)

If you wanted to get philosophical, perhaps you might paraphrase Pascal, and say: "object/Object in .NET is that Type whose center is everywhere, and whose circumference is nowhere." With "nowhere" equal to null :)


这篇关于什么是对象关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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