Why typeof(int).ToString() is not constant?
问题 I'm trying to do this: const string intType = typeof(int).ToString(); switch (typeof(MyT).ToString()) { case intType: { return "int"; break; } ... } But compiler says: error CS0133: The expression being assigned to 'intType' must be constant As I know, typeof operator works at compile-time. So, what's wrong? 回答1: As I know, typeof operator works at compile-time. You don't know that because knowledge has to be true . Where did you get the idea that typeof is executed at compile time? It