C# Unicode 字元轉義序列
Unicode 字元轉義序列表示一個 Unicode 字元。unicode-escape-sequence:(unicode 轉義序列:)
/u hex-digit hex-digit hex-digit hex-digit(/u 十六進位制數字 十六進位制數字 十六進位制數字 十六進位制數字)
/U hex-digit hex-digit hex-digit hex-digit hex-digit hex-digit hex-digit hex-digit(/U 十六進位制數字 十六進位制數字 十六進位制數字 十六進位制數字 十六進位制數字 十六進位制數字 十六進位制數字 十六進位制數字)
Unicode 轉義序列表示由“/u”或“/U”字元後面的十六進位制數字構成的單個 Unicode 字元。由於 C# 在字元和字串值中使用 Unicode 程式碼點的 16 位編碼,因此從 U+10000 到 U+10FFFF 的 Unicode 字元不能在字元中使用,在字串中則用一個 Unicode 代理項對來表示。不支援程式碼資料點在 0x10FFFF 以上的 Unicode 字元。
不執行多次轉換。例如,字串“/u005Cu005C”等同於“/u005C”,而不是“/”。Unicode 值 /u005C 是字元“/”。
示例
class Class1
{
static void Test(bool /u0066) {
char c = ’/u0066’;
if (/u0066)
System.Console.WriteLine(c.ToString());
}
}
表明了 /u0066(它是字母“f”的轉義序列)的一些用法。該程式等效於
class Class1
{
static void Test(bool f) {
char c = ’f’;
if (f)
System.Console.WriteLine(c.ToString());
}
}