Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.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# Screen.PrimaryScreen.DeviceName中的字符无效_C#_.net_Windows Xp - Fatal编程技术网

C# Screen.PrimaryScreen.DeviceName中的字符无效

C# Screen.PrimaryScreen.DeviceName中的字符无效,c#,.net,windows-xp,C#,.net,Windows Xp,我在运行Windows XP的.Net中发现了一个bug。Screen.PrimaryScreen.DeviceName或Screen.AllScreens[]的字符串值在末尾包含空字符和内存缓冲区中的垃圾。Windows 7中不存在此问题。问题是-是否有Windows Update KB可以修复此问题 在XP上尝试以下操作: Text = string.Format("{0}: {1}", Screen.PrimaryScreen.DeviceName.Length,

我在运行Windows XP的.Net中发现了一个bug。Screen.PrimaryScreen.DeviceName或Screen.AllScreens[]的字符串值在末尾包含空字符和内存缓冲区中的垃圾。Windows 7中不存在此问题。问题是-是否有Windows Update KB可以修复此问题

在XP上尝试以下操作:

Text = string.Format("{0}: {1}",
       Screen.PrimaryScreen.DeviceName.Length, 
       Screen.PrimaryScreen.DeviceName);

通常结果是:31:\\显示1。正确的长度是12而不是31。显示1后有\0,因此字符串看起来正常,但对于字符串比较,它是错误的。

这似乎是.Net/XP中的错误,Windows update无法修复。我的解决办法是:

string dev = Screen.PrimaryScreen.DeviceName;
int eos = dev.IndexOf( '\0' );
if ( eos != -1 )
  dev = dev.Substring( 0, eos );