应System.Object的的基本类型是相同的接口?接口、类型、基本、System

2023-09-04 22:38:47 作者:红颜为君舞

摘要

的typeof(ISomeInterface).BaseType ; 的typeof(对象).BaseType 也是定义。因此:

typeof(ISomeInterface).BaseType is null; typeof(object).BaseType is also null by definition. Thus:

typeof(object).BaseType==typeof(ISomeInterface).BaseType -> true 

这可能(语义)平均 System.Object的是一个接口,也没有了吗?在C#中,所有的类 System.Object的继承,但接口不。实际上接口合同,而不是基的任何类型的,而且只能从其他接口派生。

It could (semantically) mean System.Object is an interface, too, doesn't it? In c#, all classes inherit from System.Object, but interfaces do not. Interfaces in fact are contracts, not the base type of any class, and can only derive from other interfaces.

所以,我想知道是否的typeof(对象).BaseType 应该是相同的接口?

So I'm wondering whether typeof(object).BaseType should be the same as interfaces?

解释

我在小学数理逻辑的方式认为这。我对待 0 的typeof(对象)作为 1 ,以便找到某种类型的基本类型就像找到一个数的因素。

I thought this in the way of elementary mathematical logic. I treated null as 0 and typeof(object) as 1, so that finding the base types of some type are just like finding the factors of a number.

在这个假设下,可以是任何类型的派生,如 0 是一个多的一个因素的任何数目。而的typeof(对象)将是任何一类的基本类型,如 1 是任何数量的因素,甚至本身。实际的返回 中的typeof(对象).BaseType ,但是,打破了这一假设。这似乎说 0 1 的一个因素,但不是任何其他号码。

Under this assumption, null could be the derivation of any type, like 0 is a multiple by a factor of any number. And typeof(object) would be the base type of any class, like 1 is a factor of any number even itself. The actual returning null of typeof(object).BaseType, however, broke this assumption. This seems saying that 0 is a factor of 1 but not of any other number.

此外,如果我们用一个方法来查找的基本类型 SOMETYPE 递归,我们不能总是说 SOMETYPE 是不是一类,因为它的 BASETYPE 的typeof(对象).BaseType 也是

Further, if we use a method to find the base type of SomeType recursively, we cannot always say SomeType is not a class because of its BaseType is null, typeof(object).BaseType is also null.

这似乎是自相矛盾,如果

It seems paradoxical if

typeof(object).BaseType==typeof(object) -> true 

要present是其基本类型本身,而不是完全的实体和合同之间的区别是什么?

to present that its base type is itself, but isn't that exactly the difference between entities and contracts?

更新:

我最初说:

这可能意味着 System.Object的是一个接口,也没有吧?

It could mean System.Object is an interface, too, doesn't it?

我想说的是似乎混淆。这是我的错了不良EX pressed描述,对不起造成集中的答案。

What I want to say is it seems confused. It's my fault of the poorly expressed description, and sorry to cause the answers focused on that.

推荐答案

BASETYPE 属性返回的基本类型的类型,它们有的在的基地类型。对于所有其他类型,它返回一个值,表明该类型不具有的在的基本类型。您可以在原来的问题提出了下列EX pression:

The BaseType property returns the base type for types that have a base type. For all other types, it returns a value indicating that the type does not have a base type. You posed the following expression in the original question:

的typeof(对象).BaseType == typeof运算(SomeInterface).BaseType

然后你建议,由于这前pression是真实的,对象 SomeInterface 似乎有相同的基本类型。然而,你的结论是有缺陷的,因为它假设为对象 SomeInterface ,在文档中的基本类型的存在对于该方法明确指出这种情况并非如此。

Then you suggested that since this expression is true, Object and SomeInterface appear to have the same base type. However, your conclusion is flawed because it assumes the existence of a base type for both Object and SomeInterface, when the documentation for the method explicitly states that this is not the case.