This is the 24th day of my participation in Gwen Challenge

The introduction

Visual Studio claims to be the first IDE in the universe, with each release adding a lot of new features and syntax sugar. It’s impossible to know all of them, but some common ones need to be remembered. This article focuses on some common shortcuts, features, and syntax.

shortcuts

List some of the most common shortcuts to using VS

Ctrl + E, D (Ctrl + k, D)

Format the entire code to make your code instantly clean.

annotation

Ctrl+K,C comment the selection

Ctrl+K,U deselect the comment content

Collapsing document contents

CTRL + M, CTRL + O folds all methods

CTRL + M, CTRL + P to expand all methods

Case conversion

Ctrl+U: All lowercase

Ctrl+Shift+U: Change all caps

Jump a specified row

Ctrl+G

Rewind to the previous cursor position

CTRL + minus is very useful

Select the text

SHIFT + END selects the END of the line

SHIFT + HOME to the beginning of the line

Ctrl+ left mouse button to select a matrix text utility

F12 related

F12=Ctrl+ left mouse click to go to the definition of the called procedure or variable

Alt+F12 lists all the results of the search and views the referenced content without the page

Shift + F12 finds all references

debug

F9 Enable/disable breakpoints

Ctrl+Shift+F9 Delete all breakpoints

F10 procedure by procedure F11 statement by statement

Ctrl+F10 run to the cursor

Window related

Ctrl+W,B Bookmarks window

Bookmarks are very easy to use, if there are thousands of lines of code, it is much faster to add bookmarks when looking for code

Ctrl+W,E Error list

Ctrl+W,S Solution manager

features

tuples

Using tuples requires the Nuget installation package System.Valuetuple

Var model = GetFullName(); Console.WriteLine(model.name); Console.WriteLine(model.age); // Custom return parameter variable (string name, string age) = GetFullName(); Console.WriteLine(name); Console.WriteLine(age);Copy the code

In c #?? ,? ,? : and? .

[?] Nullable type modifier

I don’t have to say much about that

[?:] ternary (operator) representation

x? y:z

Return y if x is true; If x is false, return z

[?] Empty merge operator (??)

a?? B returns to B when a is null, and returns to A when a is not null. The empty merge operator is the right associative operator, that is, the operator combines from right to left. Such as, “a???? b?? C) press a?? (b?? C) “.

[?.] NULL View operator

int? age=list? .FirstOrDefault()? .Age; If the object is NULL, the Age of the object is Age

Pattern Matching

In C#7.0, matching mode was introduced, for example. An object type. We want to determine if it is an int. If it is an int we add 10 and print:

object a = 1; If (a is int) //is judge {int b = (int)a; Int d = b+1; / / add 10 Console. WriteLine (d); / / output}Copy the code

So in C#7.0, the first is a small extension to is, we just need to write it like this:

object a = 1; If (a is int c) {int d = c + 10; Console.WriteLine(d); }Copy the code

What if there are multiple types to determine, use switch

 static dynamic Add(object a)
 {
	 dynamic data;
     switch (a)
     {
         case int b:
          data=b++;
          break;
         case string c:
          data= c + "aaa";
          break;
         default:
          data = null;
          break;
     }
	 return data;
 }
 
 static void main(){
 	object a = 1;
    var data= Add(a);
    Console.WriteLine(data.GetType());
    Console.WriteLine(data);
 }
Copy the code

Recommended plug-in installation

CodeMaid

CodeMaid is an open source Visual Studio extension that cleans up and simplifies coding for c#, c++, F#, Vb, and more.

reference

Dry goods coming! New C# 7.0 features (available in VS2017)