The curator today asked the question: "In what case is System.Int32 used instead of int , System.String instead of string , and so on when declaring a type?"

It's the same thing, right? But he said that there are situations when you need to specify System.* .

Reported as a duplicate by the participants Grundy , Athari , aleksandr barakin , cheops , Streletz 24 May '16 at 7:51 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    Can be used in any way, from the point of view of the language is the same. - VladD
  • one
    It can be assumed that it is meant to get a type by its name, through reflection - there, probably (did not check), only a "strict" type name is allowed. - nzeemin
  • 3
    nameof(System.Int32) compiled, but nameof(int) is not. - i-one
  • @nzeemin: Yeah, you're right: ideone.com/JflwaE - VladD
  • one
    @VladD, some strange check :-) int , etc. Well this is for the time of the compile-time only, and reflection at run-time - naturally there can be nothing like it - Grundy

1 answer 1

int is a keyword that, in turn, is a pseudonym for System.Int32 . It is carved in the specification, therefore it is not subject to interpretation and changes. Therefore, there are no such situations in the C # language.

All this applies to other "built-in" types (string, float, object, etc.).


Although this is not directly related to the question, however, int will not be able to be used in the nameof expression - you have to use System.Int32 . Although such use, in my opinion, is interesting only in the cognitive manner and has no practical application.