Useful Visual Studio Features

From TRCCompSci - AQA Computer Science
Revision as of 09:22, 11 April 2017 by Jared (talk | contribs) (KeyBindings: added .)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Breakpoints

Visual studio allows the use of breakpoints which pauses the program once the code has reached that line, once a breakpoint has paused the program it is possible to see what is stored in each variable. This is extremely useful for large programs when running into null exceptions, as it displays which variable is null. After using a breakpoint the tool bar at the top will allow the code to run one line at a time. To place a breakpoint click on the bar left of the numbers until a large red circle appears.

Colours

Visual studio includes the ability to colour certain code, this is useful for programs that have a lot of similar names. An example of the colouring is when declaring a variable:

int i = 0;

would have int coloured as blue much like the "syntaxhighlight" feature, by default this is customisable from properties. While this may not seem useful when the extent of a program is reading and writing to consoles, it is extremely useful when using custom namespaces with their own functions and methods.

Navigation

Visual studio contains some useful features when going through code to follow what is happening. The two most used features are go to/peek definition and go to implementation. Go to definition goes straight to where something is initially defined, whether it is a variable or a function, on the other hand peeking definition places a small window within the screen that shows the same as the definition. Go to implementation goes to where a function is implemented, it is possible to go to them by double clicking.

Find all references is another fairly useful feature as it shows each time a variable or function is used.

Intellisense

Intellisense is the autocomplete function of visual studio. It is possible to gain access by pressing control space when part way through typing, this will display all possible finishes. To navigate and finish press up, down and tab. Double pressing tab allows the implementing of a template example, this is useful when creating custom exceptions or for loops. Another feature is rename. Right click on the point where a variable is defined, click rename and all uses will be correctly renamed

Right clicking on a variable and pressing "quick actions and refactorings" gives the ability to "encapsulate field and use property" or "encapsulate field but still use field". By encapsulating a variable it creates "getters" and "setters" which is a method of keeping a variable private but using or manipulating it elsewhere. Choosing to use property will replace every use of the variable with the new getter or setter, whereas using the field will keep all references the same and generate the getter and setter.

Class Diagrams

Right clicking the solution on the right and going to view on the drop down allows viewing a class diagram, this allows viewing every class, going to the code and other useful features. Each class has a drop down containing methods and fields.

There is another diagram in earlier VS, however I could not find it in 2015. It creates a hierarchy diagram. This may be included in a package I have not installed.

KeyBindings

There are many useful keybindings, many of which are common such as control + f to find all and gain access to replace.

Control + K: This allows additional commands.

Control + . (full stop): This allows the quick actions and refactorings on selected section.

Alt + LMB: This allows dragging down on multiple lines to type the same thing vertically, for example having all your variables and wanting to add public would consist of dragging down at the start and typing public.

Control + C after control + K: Comment out the selected section.

Control + U after control + K: Uncomment out section.