debugging - How do you use the Immediate Window in Visual Studio? -


The immediate window is very useful tool for debugging applications, which can be used to execute code statements In terms of break points are valid and inspect the values. I also use it to type the code snippet to know the language characteristics.

How do you use the instant window?

A good feature of an instant window in Visual Studio is the ability to evaluate the value of a method , Especially if it is called by your client code but it is part of not in a variable assignment debug mode, as mentioned, you can interact with the variable and execute the expression in the memory One who can be able to do this is important Plays a major role. For example, if you have a static method that sumes the sum of two numbers like:

  Private static inteus (int a, int b) {a + b return; }  

Then in the instant window, you can type the following:

 ? GetSum (2, 4) 6  

As you can see, it works really well for a steady way. However, if the method is non-static then you need to interact with the context of the object.

For example, suppose what your class looks like:

  private class fu {public string GetMessage () {return "hello"; }}  

If the object is already present in memory and it is in scope, you can call it in the instant window, as long as it first Your institute has been performed at the current breakpoint (or, at least, before the code has been paused in debug mode):

 ? Foo.GetMessage (); // object 'foo' already exists "hello"  

In addition, if you want to interact and test directly without having to depend on the current installation in memory You can see your Auto example in the instant window:

 ? Fu fu = new foo (); // New example of 'Foo' {temp.Program.Foo}? Foo.GetMessage () "Hello"  

If you want to further evaluate, calculate, etc., then you can move it one step further and temporarily allot the results of the method in the variable can do. > ? String msg = foo.GetMessage (); "Hello" ? Msg + "there!" "Hello!"

In addition, if you do not want to declare a variable name for any new object and only want to run one of your methods / functions then do this:

< Pre> ? New fu () GetMessage () "Hello"

A very common way of looking at the value of a method is to choose a class name and select 'Add Watch' so that you have its current However, once again, the object should be immediately and within the scope to display a valid value. This is very less powerful and more restrictive than the immediate use of the window.

With inspection methods, you can do simple math equations:

 ? 5 * 6 30  

Or compare prices:

 ? 5 = 6 6 liars? 6 == 6 true  

Question mark ('?') Is unnecessary if you are in the immediate window but it is included here for clarity (difference between words typed in expressions To get the result vs.) However, if you are in the command window and need some quick things in the immediate window, then '?' Before your statement And you go out.

, but sometimes it may be slightly inconsistent. In my experience, it is only available in debug mode, but not in the design, in non-debug mode.

Unfortunately, another drawback of the immediate window is that it does not support the loop.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -