Visual Studio Tip:  Quick Actions and Refactoring – Quickly convert for-to-foreach

Visual Studio Tip: Quick Actions and Refactoring – Quickly convert for-to-foreach

Visual Studio 2017 IDE provides its own quick refactoring capabilities using Quick Actions and Refactoring. Refactoring is a procedure to reform our code without altering the functional intent and which is easier to maintain, read and support. There are several third-party extension and tool that also allows extended code and editor level refactoring. First of all, performing a quick action using the light bulb inside Visual Studio IDE is not new. Furthermore, to different releases of Visual Studio, new refactoring options for code is getting added within the IDE. In addition, now the IDE support refactoring for convert for-to-foreach and vice versa.

Convert to ‘foreach’ using quick action:

You can find this new feature with the Visual Studio 2017 version 15.7 Preview 4. While you are using for-to-foreach loop, you can just check out for Quick Action icon (Shortcut Ctrl +.) It will show you the potential fixes.

 

convert for-to-foreach : Quick action and refactoring

Post the quick action, you can directly apply the changes or validate the overall changes in Preview Changes Windows and post that click on Apply.

 

convert for-to-foreach : Quick Action Preview Changes

Addition to for-to-foreach, you can also make private fields read-only using the quick refactoring in Visual Studio.

 

Quick Actions let you easily refactor, code with a single action. Quick Action Refactoring in Visual Studio is immensely powerful productivity tool which you can leverage for several aspects. You can quickly add a reference to a NuGet package in Visual Studio use the Quick Actions in Visual Studio to upgrade project’s language version

Quick Action Refactoring
You can also apply code fix for code analyzer rules violation generating new code and applying another code refactoring.

 

10 Effective Debugging Tips for .NET Developer

 

Hope this helps

Geek's Choice

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.