Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

structs, enums, classes, interfaces, anything else?

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?

like image 850
nawfal Avatar asked May 12 '13 19:05

nawfal


2 Answers

There are also arrays and delegates, although those are actually classes.

There are also references (ref parameters to methods) and generic type parameters in definitions of generic methods or types.

In unsafe code, there are also pointers.

like image 61
SLaks Avatar answered Oct 03 '22 12:10

SLaks


Not sure is this is a direct answer to your question but .NET has 5 types:
class, struct, interface, delegate, and enum

Common Type System

like image 22
paparazzo Avatar answered Oct 03 '22 11:10

paparazzo