4
可能重複:
How can I get the primitive name of a type in C#?C#,反射和原始類型
我在C#以下代碼:
Assembly sysAssembly = 0.GetType().Assembly;
Type[] sysTypes = sysAssembly.GetTypes();
foreach (Type sysType in sysTypes)
{
if (sysType.IsPrimitive && sysType.IsPublic)
Console.WriteLine(sysType.Name);
}
該代碼輸出:
布爾,字節,字符,雙,Int16的,的Int32,Int64的,IntPtr的,爲SByte, 單,UINT16,UInt32的,UINT64,UIntPtr,
我想通過bool
通過byte
和更換Boolean
,Byte
所以在可能的時候,不依賴於固定的數組或字典。有沒有辦法做到這一點?
它像一個魅力。謝謝。 – 2012-04-26 17:39:00