Difference between revisions of "Useful Visual Studio Features"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Added quick actions and refactorings)
Line 5: Line 5:
 
==Colours==
 
==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:<syntaxhighlight lang="csharp">int i = 0; </syntaxhighlight> would have int coloured as blue much like the "syntaxhighlight" feature, by default this is customisation 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.
+
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:<syntaxhighlight lang="csharp">int i = 0; </syntaxhighlight> 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==
 
==Navigation==

Revision as of 14:22, 13 March 2017

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.

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.

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

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