为什么这两个字符串返回不同的长度值。 “CertificateKey”是一个属性。它返回 41 的长度。但是,等效的常量字符串返回 40。如果我将证书的值复制为常量,则长度返回 41。为什么?!?
// This is the property. Length 41
CertificateKey.Length
41
// This is a constant of the same string. Length 40
"9FE90CA8A4138F65E9E2C67D1F37B9D5B9919384".Length
40
// This is a copy of the value of the property above. Length 41
"9FE90CA8A4138F65E9E2C67D1F37B9D5B9919384".Length
41
最佳答案
我将你的两个字符串文字复制并粘贴到 LINQPad 中,发现我可以重现你的结果,所以我像这样打印每个字符:
var a = "9FE90CA8A4138F65E9E2C67D1F37B9D5B9919384";
var b = "9FE90CA8A4138F65E9E2C67D1F37B9D5B9919384";
foreach (char c in a) Console.WriteLine($"{(int)c:X}");
Console.WriteLine("---");
foreach (char c in b) Console.WriteLine($"{(int)c:X}");
得到如下结果:
39
46
[...]
34
---
200E
39
46
[...]
34
200E
是 left-to-right mark 。
关于C# 字符串长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51814931/