Where are the type names indicated?

When you get the type of the variable, you can check its name:

if (my_type.Name=="Int32")

however it would be more elegant to write

if (my_type.Name==TypeNames.Int32)

to avoid typos. I can define such a class on my own, but maybe there is a definition somewhere?

If yes, where?


Note . Please avoid asking yourself: β€œWhy do you want to get the type of a variable in the first place,” β€œit’s better to use aβ€œ have, ”etc. Thank you so much!


Edit : in the meantime, I jumped to the conclusion, it would be enough to ignore the type of the object (the variable my_type) and instead check the object. In other words, my_type is not required. I forgot about the null case :-( Less code, more sleep, what I need ;-)

+3
2

typeof(Int32).Name

, , . .

if ( m_type == typeof(Int32) ) { 
  ...
}
+16

. CLR ( ConstructName ) .

JaredPar .

+2

Source: https://habr.com/ru/post/1752778/


All Articles