是否可能在c#中获取别名类型的类型?
在什么地方可以找到别名吗是否可能在c#中获取别名类型的类型?,c#,c#-3.0,C#,C# 3.0,在什么地方可以找到别名吗 Type.GetType("System.String") 返回null“别名”是语言定义的一部分。你需要在问题中查找它们。它们被编译掉了,并且在运行时不存在——string变成System.string,int变成System.Int32,等等。这是不可能通过编程实现的,因为“别名”实际上是C#中引入的关键字,而Type.GetType(和其他框架方法一样)是语言独立框架的一部分 可以使用以下值创建字典: Type.GetType("string") CLS中未定
Type.GetType("System.String")
返回
null
“别名”是语言定义的一部分。你需要在问题中查找它们。它们被编译掉了,并且在运行时不存在——string变成System.string,int变成System.Int32,等等。这是不可能通过编程实现的,因为“别名”实际上是C#中引入的关键字,而Type.GetType
(和其他框架方法一样)是语言独立框架的一部分
可以使用以下值创建字典:
Type.GetType("string")
CLS中未定义别名(int、bool等)。它们只是编译时常量,在运行时被替换。这意味着,当您的程序正在运行,并且您可以“以编程方式”执行操作时,别名已经消失。您只能执行以下操作:
bool System.Boolean
byte System.Byte
sbyte System.SByte
char System.Char
decimal System.Decimal
double System.Double
float System.Single
int System.Int32
uint System.UInt32
long System.Int64
ulong System.UInt64
object System.Object
short System.Int16
ushort System.UInt16
string System.String
Type.GetType(typeof (string).ToString())