Visual Studio Quick Actions

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

The Quick Actions lets you easily refactor, generate, or otherwise modify code with a single action.

  • With Quick Actions you can fix errors in code that would cause a build to fail.
  • When Quick Actions are available to fix an error on a line of code, the icon that's displayed in the margin or underneath the red squiggle is a light bulb with a red 'x' on it.

Types

The icon that appears when a Quick Action is available gives an indication of the type of fix or refactoring that's available.

  • Screwdriver: Indicates there are actions available to change the code, but you shouldn't necessarily use them.
  • Yellow Light Bulb: Indicates there are actions available that you should do to improve your code.
  • Error Light Bulb: Indicates there is an action available that fixes an error in your code.

Let's consider the following code where accidentally int is written as itn.

image

When you hover the mouse at the location of an error and if a fix is available, light bulbs appear.

image

To see potential fixes, select either the down arrow next to the light bulb or the Show potential fixes link. A list of available Quick Actions is displayed.

image

Now let's select the right action, like Change the itn to int and you will see that it automatically fixes the issue.

image

The Quick Action also enables you to remove variables that have been declared but never used in your code.

image

For more information about the quick actions in Visual Studio, visit the official documentation page https://docs.microsoft.com/en-us/visualstudio/ide/common-quick-actions



Got any Visual Studio Question?