C# - 可变不在目前的情况下存在 [英] C# - Variable does not exists in current context
问题描述
我有一个问题,我似乎无法来解决。
我创建了一个类函数调用的测试,并在功能我声明的变量。
在下一行我填一个字符串的函数。
在调试过程中的变量不声明,我在VS变量观察家告诉我,该变量不存在于当前上下文。
大家能帮我解决这个问题?
下面是我的代码:
公共无效测试()
{
串目录路径;
目录路径= System.Environment.GetFolderPath(System.Environment.SpecialFolder.InternetCache);
}
我的猜测是你使用Release配置 - 优化可能已删除该变量,因为它比毫无意义的调试等。您分配一个值,但从来没有看过。在调试配置,我希望它被罚款(但可能创建一个警告)
编辑:当然,这是假设你的在的的测试()
方法,你不能看到变量。如果测试()
已经然后Likurg的答案可能是比较合适的完成。
I have a problem I can't seem to solve.
I created a class function called test and in the function I declared a variable. On the next line I fill the function with a string.
During debugging the variable does not get declared, my variable watcher in VS tells me that the variable does not exists in the current context.
Can you all help me solve this problem ?
Here is my code:
public void Test()
{
string DirectoryPath;
DirectoryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.InternetCache);
}
My guess is you're using a Release configuration - the optimizer may have removed the variable, as it's pointless other than for debugging. You assign it a value, but never read it. In a Debug configuration, I'd expect it to be fine (but possibly create a warning).
EDIT: Of course, this is assuming that you were in the Test()
method that you couldn't see the variable. If Test()
had already completed then Likurg's answer is probably more appropriate.
这篇关于C# - 可变不在目前的情况下存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!