Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.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#中,如何获得以Unicode格式打印的字符的最小值和最大值?_C#_Unicode_Char - Fatal编程技术网

在C#中,如何获得以Unicode格式打印的字符的最小值和最大值?

在C#中,如何获得以Unicode格式打印的字符的最小值和最大值?,c#,unicode,char,C#,Unicode,Char,根据MSDN,字符的最小值为U+0000,最大值为U+ffff 我编写了以下代码来打印相同的内容: using System; using System.Collections.Generic; using System.Linq; namespace myApp { class Program { static void Main() { char min = char.MinValue; char max = char

根据MSDN,字符的最小值为U+0000,最大值为U+ffff

我编写了以下代码来打印相同的内容:

using System;
using System.Collections.Generic;
using System.Linq;

namespace myApp {
    class Program {
        static void Main() {
            char min = char.MinValue;
            char max = char.MaxValue;
            Console.WriteLine($"The range of char is {min} to {max}");
        }
    }
}
但是我没有得到U+0000和U+ffff格式的输出


如何获取它?

您的问题是,当格式化为字符串时,
char
已经表示为字符。我的意思是值为0x30的
char
表示为
0
,而不是
48

因此,您需要将这些值转换为
int
,并以十六进制显示它们(使用格式说明符
X
):

查看其数字(十六进制)值

结果:

The range of char is U+0000 to U+ffff

你想用十六进制把它们打印成整数。是的,十六进制,但前面有U+,这给了我想要的输出,但是不使用U+{min}就可以得到U+0000的输出吗?@puregeek不,我不这么认为。如果我以unicode值(如U+0000)的形式输入,那么(afaik)没有内置的方式来表示“将此字符作为unicode值打印”C#是否可以识别为字符,或者我是否必须将其作为0000?
The range of char is U+0000 to U+ffff