Editor's note:  The following post was written by ASP.NET MVP Patrick Desjardins

Three Top Features That Will Help Improve Your Productivity with Visual Studio 2013

Visual Studio 2013 is packaged with a lot of new features. Three of them will be your next best friend. Not only are they easy to use but they don’t require a lot of deep configuration to activate. We will discuss enhanced debugging that shows the return value, the possibility of rapid access to the code that is used anywhere in the code editor window and how to improve navigability inside your files.

The first feature is an enhancement when you are debugging. It’s now possible to see the return value of a method. It’s available directly from the Autos Window, inside the Watch Window or can be displayed with a command inside the Immediate Window. To be able to see the return value, you need the caret at the method’s ending curly bracket. This is a logical place to be because this feature allows you to see the returned value of the method you are in. This feature is only available if you are debugging.

Once you are correctly positioned you can type the variable $ReturnValue into the Immediate Window and hit the Enter key to display the returned value. The value will be displayed right below the command. If your Immediate Window is missing in debug, simply go to Debug, Windows, Immediate.

 

It can be accessible with the $ReturnValue keyword typed directly into the Immediate Window as we just saw, but is also available in the Watch Window. In both cases, the dollar sign is required to be able to see the value. This variable can be handy to have in the Watch Windows since it’s always available in each of your methods when testing. If you do not see your Watch Windows, go to Debug, Windows, Watch when debugging.

 

Another possibility is to use the Autos Window. You need to go to Visual Studio under Debug, Windows, Autos to activate the windows.

 

 

This is even more interesting than both of the previous windows. First, because you have nothing to write, it’s automatically available for you. Second, if we have a method that calls another method within the return value, both return values will be displayed. This means that the value of $ReturnValue is displayed as previously but also underlying return value from the other method. Here is a snippet of code that displays a method named “Method1” that calls another method called “Method2” and so on until it reaches “Method3”.

class Program

{

        static void Main(string[] args)

        {

            var x = Method1();

        }

 

 

        private static string Method1()

        {

            return "Method1 call " + Method2();

        }

 

        private static string Method2()

        {

            return "From Method2 " + Method3();

        }

 

        private static string Method3()

        {

            return "From Method3";

        }

}

If we have a breakpoint at the ending curly bracket of Method1, we will see in the Auto Window the 2 lines. The first line is the “Method2” returned value and the second line is the returned value from “Method1”. This is quite powerful to not only know the returned value of the debugged method but also the one used in the return statement.

 

The second feature that will be in your development belt is called Peek Definition. Peek Definition improves your productivity by allowing you to display code that is outside the current file. This means that if you are using a method from a class that resides in another file, you do not need to switch back and forth between those two files. To see the content of a method, you only need to hit the shortcut ALT+F12 and the method’s code will expand below the method call, inside a panel. At first, it may look like a simple addition to Visual Studio but after a few minutes Peek Definition shines by improving the organization of your workspace file. Now, files for reading do not need to stay open.  It’s fast to use, reduces the amount of open files in your Visual Studio workspace and it allows you to code faster because you do not need to switch your focus.

Here is an example. Let’s say that the “Program” class is in one file, the “OneClass” is in another while the “TwoClass” is in a third. If you are writing code inside the “Main” method of “Program” class and want to have a quick look of “OneMethod”, before Visual Studio 2013, you had to open the “OneClass” file and close it.

    class Program

    {

        static void Main(string[] args)

        {

            var one = new OneClass();

            var oneMethodResult = one.OneMethod();

        }

    }

    public class OneClass

    {

        public string OneMethod()

        {

            int i = 110;

            string message = "This is a string";

            return string.Concat(message,i, new TwoClass().TwoMethod());

        }

    }

    public class TwoClass

    {

        public string TwoMethod()

        {

            return "This is from TwoClass";

        }

    }

 

Now, with Visual Studio 2013, you just need to hover the method you want to access and hit Alt+F12 or right click on the method and select Peek Definition.

 

 

This will open the Peek Definition window.

 

From here you have more options. The first one is to simply take a look and close the window. This can be very fast with the shortcut Alt+F12 to open Peek Definition window and to press the Escape key to close the window. Furthermore, you can edit the code inside Peek Definition. That mean you can do quick edits without leaving the code you are developing. This is the essence of this feature: limit your focus on the current task you are coding. If you need to have more than quick access, you can click the folder icon at the top right of the Peek Definition window. This will open the file that contains the method currently Peeked. The last move you can do with the Peek Definition is to Peek Definition the Peek Definition! Not only can you see the code of one method but you can also see the code under the method that you Peek. If we look back at the example above, you can also see what “TwoMethod()” contains by pressing again on Alt+F12.

 

This time, a navigation menu built with a blue dot appears. When you click the first dot, you go in to the Peek Definition of the first method. If you click the second dot, you Peek the inner method of the Peek Definition. This feature is very handy and will help you to keep focusing on the code you are working without having many files remaining open for no reason.

 

The third features is an improvement of the scrollbar. With Visual Studio 2013, it’s possible to see a map of your code directly in the scrollbar. This allows to have a big picture of the current file and to click on it to have fast access to a specific part. Not only is the navigation easier but it simplifies code refactoring by giving easier access to sections of the file. To activate this feature, you need to right click on any scrollbar and select “Scroll Bar Options…”.

 

 

From here you can select a new behavior called “Use map mode for vertical scroll bar”. This will enlarge the vertical scroll bar by the size you select from the source overview drop down. The example below displays a medium definition.

 

Having the new scrollbar activated in “map mode” produces the following effect.

 

You now have an overview where you are located in the file and can quickly find the portion you may want to move to. Finally, the map scrollbar has an option to preview the mapped code inside a tooltip. As you may have noticed, the scrollbar does have a white section that represents the portion that is displayed at the screen. If you move your cursor anywhere at the scrollbar you will see a tooltip with the code in a bigger format which is readable. The screenshot below displays the tooltip in action (labeled “1”) and the the current code displayed in the editor (labeled “2”).

 

 

Your productivity should improve with these 3 features. One allows you to quickly see what is returned. This solves the problem that we had to know the return value by declaring an additional variable just before the return statement . The second allows us to focus on the main task in your development. The Peek Definition is the way to navigate the code for a short time without losing focus or having to open many files that stay open for nothing. Last, we have seen how to use the scrollbar as a map of your code. With the trend of wide screen, this scrollbar is perfect for every developer by using dead space to improve a quick way to navigate inside each of your files.

About the author

Patrick Desjardins is programming since 2000 and has been focusing is knowledge on web since 2002. He has a broad knowledge of the web by developing with PHP and Asp. Since few years he is developing exclusively with Asp.Net MVC which is his favorite framework. Patrick likes to develop solution that is easily maintainable and scalable. This is why he loves to refine how to design web site to have good design pattern without over doing it. Patrick also have work on many websites, about half and half on intranet and extranet and has various experiences which has lead him to be Microsoft Asp.Net MVP for 2013. You can find his blog at http://patrickdesjardins.com/blog and can contact him on Twitter @MrDesjardins in English or in French.