Let’s learn below a Visual Studio Tip: Quickly convert for to foreach loop. Visual Studio 2017 IDE provides quick refactoring using Quick Actions and Refactoring. Refactoring is a process of reforming our code without changing its functional purpose and making it easier to maintain, read, and support.

There are a number of third-party extensions and tools that also allow for extensive and editor-level code refactoring. First of all, doing quick work with a lightbulb in the Visual Studio IDE is not new. Additionally, in different versions of Visual Studio, new code refactoring options are added to the IDE. Additionally, the IDE now supports refactoring for for to foreach conversions and vice versa.

Convert to ‘foreach’ loop using Visual studio quick action:

You can find this new feature with Visual Studio 2017 version 15.7 Preview 4. While using for-to-foreach loop, you just need to find the quick action icon (shortcut Ctrl+.) It will show give you potential fixes.

Visual Studio Tip:  Quickly convert for to foreach

Publish quick actions, you can apply changes directly or make global changes in the Changes Preview window and publish by clicking Apply.

Visual Studio Tip:  Quickly convert for to foreach

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 and write code with just one action. Quick Action Refactoring in Visual Studio is an extremely powerful productivity tool that you can leverage for a number of aspects. You can quickly add references to NuGet packages in Visual Studio by using Quick Actions in Visual Studio to upgrade your project’s language version.

Visual Studio Tip:  Quickly convert for to foreach

11 Effective Debugging Tips for .NET Developer



You can also apply code fixes to code analyzer rule violations by generating new code and applying different code refactoring.

You can check more article on our website under C# section HERE or you can also check same on Microsoft Docs too.

Leave a Reply

Your email address will not be published. Required fields are marked *

Explore More

Working With File Class In C#

In C#, ‘File’ class provides many static methods for moving, copying, and deleting files. These Static methods involve moving a file and copying and deleting a file also. Let’s check

How to Read a Text File in C#

In C# ‘File’ class provides static methods to read given text file data. The File.ReadAllText() method opens a text file, reads all the text present in the file into a

C# | How to use Interface references

In C#, you’re permitted to make a reference variable of an interface type or in other words, you’re permitted to form an interface reference variable. Such kind of variable can