开发者

debugging in VS 2010

This might sound silly but I'm new to debugging a web app. What's the difference between 开发者_开发百科F11 and F10 when debugging. Also, how can you add a variable to the watch window? Can you right click on it and add it?

Thanks


See comments inline:

public void Method1()
{
    ExecuteMethod2();   //<------Pressing F10 here, the debugger will take go to the next line (initialize iTemp) 
                        //and it would have executed ExecuteMethod2()
                        //---Pressing F11, the debugger will step in the ExecuteMethod2() and you would be able to 
                        //debug each line in that method. After the method ends, the debugger would return to the Method1() and continue

    int iTemp = 0;
}

public void ExecuteMethod2()
{
    .....
}

To answer your other question, while debugging, you can right click on the variable and add to watch window.


F10 is Step Over. Pressing F10 will execute the entire next statement.

F11 is Step Into. Pressing F11 will step into the first function called by the next statement, allowing you to debug that function.


F10 - If the next line of code calls another method/function somewhere else or in some other code the debugger will execute it but will not step through it line by line. You'll just see the debugger move to the next line in the piece/page of code you're currently looking at.

F11 - the debugger will follow any execution through line by line, so if that line of code calls another method or accesses data from somewhere else or another class it will step through that as well - jumping from class to class if necessary. I think of this as recursive.

class A{
    public static void main(string[] args){
        A.method1();
        A.method2();
        A.method3(B.GetMeAnArrayofSomething());
        B.method4();
    }
}

class B{
    public GetMeAnArrayOfSomething(){
        string[] myArray = new string[5];
        for(int i=0;i<=5;i++){
            //dosomething repetive
        }
        return myArray;
    }
}

So you're stepping through class A's main method. When you get to A.method3 you could press F10 and move the line selector to A.method4() OR you could hit F11 and step through class B's GetMeAnArrayOfSomething method line by line as preferred.

You can right click and select 'Add Watch' to add variables/objects to the continuous watch window. Also the Quickwatch function which adds it to a less permanent view. Personally I use the Immediate window a lot. Its commandline-based so quick and easy if you like that sort of thing (I do).

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜