为什么在System.Object的.NET不是抽象的? [英] Why is System.Object not abstract in .NET?

查看:160
本文介绍了为什么在System.Object的.NET不是抽象的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道它是常用的锁定对象,但事实是否真的足够的理由? 是什么意思

I know it is commonly used as a lock object, but is that really sufficient reason? What is the meaning of

object o = new object();

这是不抽象类是重新presents实际物体的东西。 asdasdf是一个字符串。有什么实际的实例可以有成为对象的类?它没有任何意义,面向对象的,明智的。我的问题是,如果有一些实际的原因,它的存在(除了被用作锁定的对象)。

An non-abstract class is something that represents actual objects. "asdasdf" is a string. What actual instance can there be of "object" class? It doesn't make sense, OOP-wise. My question is if there is some practical reason for its existence (besides being used as a lock object).

推荐答案

有时候,你只需要一个对象,而不是其他,在使用的东西,像实现多线程锁随机引用类型等。赚不到对象的抽象允许在这些情况下使用。该Monitor.Enter和Monitor.Exit类(这是落后于C#中的锁定关键字的基础上)可以在任何给定的对象上获取一个锁,而不管实施。

Sometimes you just need an Object, and nothing else, such as when using a random reference type for things like implementing multithreading locks. Not making object abstract allows use in those situations. The Monitor.Enter and Monitor.Exit classes (which is the basis behind the "lock" keyword in C#) can acquire a lock on any given object, regardless of implementation.

这篇关于为什么在System.Object的.NET不是抽象的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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