Introduction
We all have a habit of using the new version of Visual Studio as it emerges in the market. Only a few have the habit of reading about its features and also learning about the usage guidelines or tips to use for betterment.
What this article is all about?
This article will help you to know a few features and also the Tips or Tricks to use the Visual Studio which in turn make your daily activities easy and smooth.
Hope this article will be a worth reading that too consumes very less time.
Some of the Tips or Tricks:
- Quick Launch and Search:
Quick launch (Qtrl+Q) is a gift that keeps on giving. You can use it to search anything you need to find in the options or in the menu.
- Roslyn
Roslyn is the new, improved, open-source .NET compiler, written from the ground up exclusively in C#.
It looks exactly the same as the editor you're used to, but offers a much better experience. A lot of modal windows have been replaced with less invasive UI analogies.
- Light bulb
Light bulb - the bulb appears when the analyser has smart refactoring options and suggestions about your code When the light bulb is not available, smart refactoring can be invoked with Ctrl+.
Inline renaming can also be invoked with Ctrl+R,Ctrl+R while the cursor lies on a specific element static using. Using this feature means that you can do away with fully qualified namespace resolution. Instead of Console.WriteLine() you can simply do this using static System.Console;
- WriteLine("Hi this is Bhuvan!");
- Dictionary Initializers:
The dictionaries can be initialized in a new way, as follows,
- static Dictionary<string, string> GetTeachers()
- {
-
- var oldStudentData = new Dictionary<string, string>
- {
- {"Bhuvan", "1001" },
- {"Prabhu", "1002" }
- };
-
-
- var newStudentData = new Dictionary<string, string>
- {
- ["Bhuvan"] = "1001",
- ["Prabhu"] = "1002"
- };
- return newStudentData;
- }
- Null Conditional Operator:
The operator checks to see if a referenced property is initialised and then returns the value. If the property under evaluation is not initialised, it will return null.
- var studAddress = student?.Address;
- Selecting Block of code:
When you want to select a complete code block very quickly. Keep you cursor either at the starting or at the ending braces, then all you have to do is Just press Ctrl + Shift + ] . You will find the complete code block is being selected.
* Select the cursor at the starting of the block and Press Ctrl + Shift + ] the entire block is selected.
- ‘forr’ code snippet for reverse ‘for’ loop:
When you type the word "forr" then, that will generate a reverse for-loop as shown below.
- for(int i=Length-1; i>=0; i--)
- {
-
- }
- “Shift+Enter” to add “;” semi-colon at end of the line automatically:
You can use “Shift + Enter” to add semicolon (;) to end of the line. Instead of putting “;” end of the line, you just press “Shift+Enter”. It will automatically add “;” at the end of the line and will move the cursor to next line.
- Exception Filters: Here the exception can be handled with "When" in the catch block:
- try
- {
- throw new Exception("myError");
- }
- catch (Exception ex) when (ex.Message == "NullException")
- {
-
- }
- catch (Exception ex) when (ex.Message == "Error")
- {
-
- WriteLine("myError Occurred");
- }
- Auto property initializer:
This "Auto property initializer" will helps to intialize values automatically , you can initialize properties with default values, without the need for a constructor, as follows
public string studentName { get; set; } = "Mili";
- Change auto-insertion of IntelliSense options as you enter code:
To enable suggestion mode, choose the Ctrl + Alt + Spacebar keys, or, on the menu bar, choose Edit, IntelliSense, Toggle Completion Mode.
- Use Built-In code snippets:
You can use built-in snippets or create your own snippets.
To insert a snippet, on the menu bar, choose Edit, IntelliSense, and Insert Snippet or open the shortcut menu in a file and choose Insert Snippet.
- Bookmark lines of code:
To set a bookmark, on the menu bar, choose Edit, Bookmarks, Toggle Bookmark. You can view all of the bookmarks for a solution in the Bookmarks window.
- Debugging Short Cuts:
Activity |
Short Cut - Key |
Start Debugging |
F5 |
Stop Debugging |
Shift+F5 |
Restart Debugging |
Ctrl+Shift+F5 |
Step Over |
F10 |
Step Into |
F11 |
Step Out |
Shift+F11 |
Run To Cursor |
Ctrl+F10 |
Set Next Statement |
Ctrl+Shift+F10 |
Set and Toggle Breakpoint |
F9 |
Disable Breakpoint |
Ctrl+F9 |
Immediate Window |
Ctrl+Alt+I |
Immediate Window Command Mode |
Type “>” |
Immediate Window Clear Buffer |
>cls |
Immediate Window Print Value |
?varname |
Read more articles on Visual Studio: