我在Windows XP上发现了.Net中的一个错误。字符串值Screen.PrimaryScreen.DeviceName
或Screen.AllScreens[]
在末尾包含额外的字符(空值和来自内存缓冲区的垃圾)。 Windows 7中不存在该问题。问题是 - 是否有Windows Update(KB)修复此问题?
试试这个(在XP上):
Text = string.Format("{0}: {1}",
Screen.PrimaryScreen.DeviceName.Length,
Screen.PrimaryScreen.DeviceName);
通常结果是:31: \\.\DISPLAY1
。正确的长度是12而不是31.在\0
之后有Display1
因此字符串看起来没问题,但是对于字符串比较它是错误的。
答案 0 :(得分:0)
似乎这是.Net / XP中的错误,Windows更新无法修复。我的解决方案是:
string dev = Screen.PrimaryScreen.DeviceName;
int eos = dev.IndexOf( '\0' );
if ( eos != -1 )
dev = dev.Substring( 0, eos );