7

I was pondering of this while I was writing some helper functions dealing with reflection. Is there anything else besides classes, structs, enums and interfaces in C#? If I write a function that checks for class, struct, enum and interface, would that be the all encompassing function?

I read that delegates are classes anyway here and here.

Help me make my idea on this kind of hierarchy perfect:

   reference type                   value type
         |                               |    
  ---------------                   ----------
  |             |                   |        |
interface    class                struct    enum


// the all encompassing function - pseudo code:
public static bool IsC#Stuff(this Type type)
{
    return type.IsEnum || type.IsStruct || type.IsClass || type.IsInterface;
}

Am I missing something?

4

2 回答 2

3

还有数组和委托,尽管它们实际上是类。

在泛型方法或类型的定义中还有引用(ref方法的参数)和泛型类型参数。

在不安全的代码中,也有指针。

于 2013-05-12T19:35:19.113 回答
1

不确定这是否是您问题的直接答案,但 .NET 有 5 种类型:
类、结构、接口、委托和枚举

通用类型系统

于 2013-05-13T03:12:14.197 回答