Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#,反射和基元类型_C#_Reflection_Primitive Types - Fatal编程技术网

C#,反射和基元类型

C#,反射和基元类型,c#,reflection,primitive-types,C#,Reflection,Primitive Types,可能重复: 我在C#中有以下代码: 此代码输出: 布尔、字节、字符、双精度、Int16、Int32、Int64、IntPtr、SByte、, 单,UInt16,UInt32,UInt64,UIntPtr 如果可能的话,我想用bool替换Boolean,Byte替换Byte等等,而不依赖固定数组或字典。有什么方法可以做到这一点吗?这是重复的 这也是双向飞碟的一个好答案 答案是,你可以,而且不用字典 Type t = typeof(bool); string typeName; using

可能重复:

我在C#中有以下代码:

此代码输出:

布尔、字节、字符、双精度、Int16、Int32、Int64、IntPtr、SByte、, 单,UInt16,UInt32,UInt64,UIntPtr

如果可能的话,我想用
bool
替换
Boolean
Byte
替换
Byte
等等,而不依赖固定数组或字典。有什么方法可以做到这一点吗?

这是重复的

这也是双向飞碟的一个好答案

答案是,你可以,而且不用字典

Type t = typeof(bool);

string typeName;
using (var provider = new CSharpCodeProvider())
{
  var typeRef = new CodeTypeReference(t);
  typeName = provider.GetTypeOutput(typeRef);
}

Console.WriteLine(typeName);    // bool

它就像一个符咒。谢谢
Type t = typeof(bool);

string typeName;
using (var provider = new CSharpCodeProvider())
{
  var typeRef = new CodeTypeReference(t);
  typeName = provider.GetTypeOutput(typeRef);
}

Console.WriteLine(typeName);    // bool