[C#] Close Encounters of the Third Type

It’s funny how people keep believing that C# is only about value types and reference types. That’s why so many people were disturbed by the riddle in my previous post:

> What other type matches neither the class nor the struct constraints ?

And the answer is obviously…

> Any pointer type, like void* or char*

Well, I admit, that was a little unfair question since pointer types can’t be used as a type argument, even if there is no constraint. You could also say void, but one would argue that it’s not a true type, since you can’t declare a variable of type void.

However, we all leave pointer types aside, but it’s an actual type like any other. Did you know that you can even get the actual Type class of a pointer ?

typeof(void*)

for instance, gives the following

Assembly: {mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
FullName: "System.Void*"
GUID: {00000000-0000-0000-0000-000000000000}
HasElementType: true
IsAbstract: false
IsAnsiClass: true
IsArray: false
IsAutoClass: false
IsAutoLayout: true
IsByRef: false
IsClass: true
IsCOMObject: false
IsConstructedGenericType: false
IsContextful: false
IsEnum: false
IsExplicitLayout: false
IsGenericParameter: false
IsGenericType: false
IsGenericTypeDefinition: false
IsImport: false
IsInterface: false
IsLayoutSequential: false
IsMarshalByRef: false
IsNotPublic: true
IsPointer: true
IsPrimitive: false
IsPublic: false
IsSealed: false
IsSerializable: false
IsSpecialName: false
IsUnicodeClass: false
IsValueType: false

By the way, I’m really curious why typeof(void*).IsClass == true. Hopefully I will write an article on that some day.