C# - Variable does not exists in current context

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);
}

Answers


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.


If i'm not mistake you want to do this

    public class MyTest
    {
        string DirectoryPath = "";
        public void Test()
        {
            DirectoryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.InternetCache);
        }
        public void UseString()
        {
            //Use DirectoryPath
        }
    }

Need Your Help

How can I style a file input field in Firefox?

html css forms file

I am currently doing the front end for a site with looooads of forms, all styled up and looking pretty in IE, but I've just noticed that in Firefox the file input fields aren't responding to any of...

CListView in Yii Framework

php frameworks yii yii-components

Hey guys i have started working on yii framework and i am following the yii blog tutorial to learn basics of yii framework in this tutorial they have used a ClistView in posts view but i am getting...