[C#] system.object类型究竟如何工作? [英] [C#] how the system.object type exactly works ?

查看:101
本文介绍了[C#] system.object类型究竟如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我确实从Microsoft Docs中读到了System.Object,但我不明白一件事。好吧,我知道.NET中的每个类都隐含地继承自System.Object,我知道当我将一个值类型传递给对象变量时,它被System.Object包装并被分配给托管堆但是当我传递给它时会发生什么System.Object是一个引用类型?它会被重新装箱还是?





顺便说一下还有一个问题:我如何能够传递我想要的所有System.Object对象?



我尝试过:



阅读微软的文档

Hi. I did read about the System.Object from the Microsoft Docs but I didn't understand one thing. Okay I know that every class in .NET implicitely inherits from System.Object and I know that when I pass a value type to object variable its getting wrapped by the System.Object and is allocated to the managed heap but what happens when I pass to the System.Object a reference type ? Is it going to be re-boxed or ?


Btw also one additional question: How I am able to pass everything i want to object of the System.Object ?

What I have tried:

Reading the Microsoft's Documentation

推荐答案

也许这篇文章会澄清: C#4.0教程:System.Object - 2016 [ ^ ]

Maybe this article will clear things up: C# 4.0 Tutorial: System.Object - 2016[^]
Quote:

当我们在值类型和对象之间进行转换时,CLR必须执行一些特殊的工作来弥合值之间的语义差异和参考类型。此过程称为装箱和拆箱。

When we cast between a value type and object, the CLR must perform some special work to bridge the difference in semantics between value and reference types. This process is called boxing and unboxing.


这篇关于[C#] system.object类型究竟如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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