在C#中,如何获得以Unicode格式打印的字符的最小值和最大值?
根据MSDN,字符的最小值为U+0000,最大值为U+ffff 我编写了以下代码来打印相同的内容:在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
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