AI Code Assistance in Visual Studio 2022

Introduction

Visual Studio IDE is one of the most popular programming tools for development. It contains so many features and helps us to write code more productively and efficiently. 

We are going to explore one of the features known as “AI code assistance in Visual Studio”. Whenever we are working on any project/solution. We usually create classes, code blocks of CRUD operations, etc. We can make use of this feature to make our coding faster. The AI engine in Visual Studio detects our code context, including variable names, functions, and the type of code we are writing. Based on that it gives you the best suggestions.

Please find the below few scenarios to have an idea, and then we can use/benefit from Visual Studio on regular usage.

Scenario 1. Create an Employee class

  1. It suggests property as Id.
    Property as ID
  2. And then, after pressing “Tab” to accept changes and clicking on the “Enter” button. It shows as possible the next field as "Name" like below.
  3. For example, we created one field named "FirstName" and then the next attribute suggested as "LastName"
  4. Here, we wanted to achieve "FullName" then it suggests below like format of "FirstName" and "LastName"

So, It Pre-populates the next set of possible fields with the most accurate suggestions from the “AI”  engine. It fits our needs in most/all of the cases.

Scenario 2. Pre-populate code

For example, we are writing code to add a method named “Sum” and take two input parameters. Then the implementation of the method will be displayed automatically as follows.

For example, For the Multiply method – the code is formatted as below as “AI” Understand the English verbal word “Multiply” and then provide code suggestions.

Scenario 3. CRUD operations Code Suggestions

For example, We are adding data to the list. The code suggestion is as follows.

After that, By clicking on the “Enter” button, it also suggests for Removal of data like below.

The following examples give some ideas and increase our productivity by utilizing this feature in Visual Studio while doing code.

Thanks for reading, and please provide your comments.

Reference


Similar Articles