【发布时间】:2008-10-08 03:20:58
【问题描述】:
好吧,这很奇怪。垃圾数据也不是随机的,它似乎是可执行文件本身的子字符串。
private void Form1_Load(object sender, EventArgs e)
{
string s = GetValue();
// at this point, s == "400". Why isn't really relevant (dumbed down a test)
if (s != "18446744073709551615")
throw new Exception();
// When the exception is thrown though, the string is set to random
// data from inside the executable.
}
这似乎取决于 GetValue() 中某些看似无关紧要的实现细节,例如对 string.Format() 的调用位于不同的位置。
有没有人遇到过类似的事情或有任何想法可能导致这种情况?
【问题讨论】:
-
我觉得GetValue()的定义不管多长都应该包含进去
-
另一个大问题是您如何检查“s”中的数据,更重要的是“何时”检查该数据?您是否在抛出异常并且“s”现在超出范围后检查它?
-
是的,这是在 VS 弹出后,它是未处理的异常内容。不过,我不记得以前发生过局部变量的情况。
-
我正在 VS 的“Locals”窗口中检查它