Why is the name (object) not allowed?

In C # 6.0 you can write this:

var instance = default(object); var type = typeof(object); 

They have the same result:

 var instance = default(System.Object); var type = typeof(System.Object); 

But you cannot write this:

 var name = nameof(object); 

It generates the following error:

Invalid expression term 'object'.

But you can still write this:

 var name = nameof(System.Object); 

Why is nameof(object) not compiling?

+7
c # nameof
source share
1 answer

The difference is that object is a synonym for the class object and nameof() does not work with synonyms.

The same goes for nameof(int) vs nameof(Int32)

+14
source share

All Articles