Loading...

Using GitHub Copilot Chat in Visual Studio

Using GitHub Copilot Chat in Visual Studio

GitHub Copilot is a coding assistant powered by Artificial Intelligence (AI), which can run in various environments and help you be more efficient in your daily coding tasks. In this new series of content, we will show you how GitHub Copilot works in Visual Studio specifically and how it helps you being more productive. I just published the third short video in this series, titled "Using GitHub Copilot Chat in Visual Studio". The video is embedded below:

 

 

Learning about code with GitHub Copilot Chat

In the video, my colleague Bruno Capuano shows sample code filling an array with random numbers. Of course arrays are cool, but the C# language is much richer and offers other classes that one can use to create lists, with various functionalities. Copilot Chat is a great companion for this kind of explorations.

 

GitHub Copilot Chat can, for example, explain the difference between arrays and Lists. The differences listed in the example mention:

  • The size (an array is a fixed-size structure while a List can grow and shrink at runtime).
  • The performance, a very important consideration (arrays are generally more efficient than Lists because they don't have the burden of dynamic sizing).
  • The functionality (a List has more methods than an array, allowing for data manipulation)

In addition, sample code is also added to the chat, illustrating the creation of an array and a List, and adding one element.

 

Note that the user didn't have to mention using C# and .NET in the Copilot chat. This context was inferred from the solution and the file currently open. This is quite similar to a conversation that you would have with a fellow coder during pair-programming.

 

Converting code

In the next example, Bruno asks Copilot Chat to convert his code, initially using arrays, to use Lists instead. A very neat feature which I personally like a lot is the preview feature. Simply click the Preview button, and the code will be shown inline in the code file, but in a very neat "diff" view, similar to what you see when visualizing differences in code, for example after a commit in GitHub.

 

For me, it's a great way to see exactly what code will be changed, and most importantly, to review the code created by Copilot before accepting the changes. As we always say in this series, this is a Copilot, but you are the Pilot in Command!

 

I reproduced the sample that Bruno is showing, and here is the before-and-after code that Copilot Chat proposed to me:

 

Before:

 

// fill an array with 10 random numbers int[] numbers = new int[10]; Random random = new Random(); for (int i = 0; i < numbers.Length; i++) { numbers[i] = random.Next(1, 100); }

 

 

After:

 

// fill a list with 10 random numbers List<int> numbers = new List<int>(); Random random = new Random(); for (int i = 0; i < 10; i++) { numbers.Add(random.Next(1, 100)); }

 

 

LBugnion_0-1711442743928.png

Asking Copilot to convert the code

 

LBugnion_1-1711442743929.png

The proposed solution

 

LBugnion_2-1711442743930.png

The Preview feature

 

Keep learning!

Even at my "advanced career stage" (after all I've been working with C# and .NET since the early 2000s when it came out), I am still learning every day and GitHub Copilot is a great companion to show me new C# features and new Visual Studio functionalities. I used to love IntelliSense, and still do, but GitHub Copilot is boosting my code, and teaching me new syntax.

 

For more information, check our collection with resources here. Also, you can see the full length video here. Stay tuned to this blog for more content posted regularly. And of course, you can also subscribe to our YouTube channel to get more video content!

Published on:

Learn more
Azure Developer Community Blog articles
Azure Developer Community Blog articles

Azure Developer Community Blog articles

Share post:

Related posts

This Month in Azure Static Web Apps | 09/2024

    We are back with another edition of the Azure Static Web Apps Community! :party_popper:   September was yet another month ...

1 year ago

GitHub Copilot for Azure: 6 Must-Try Features

As developers, we are constantly seeking tools that streamline our workflows and boost productivity. … Enter GitHub Copilot for Azure, now in ...

1 year ago

Responsible AI Mitigation Layers

Generative AI is increasingly being used in various kinds of systems to augment humans and infuse intelligent behavior into existing and new a...

1 year ago

Streamline Your Azure Workflow: Introducing GitHub Copilot for Azure in VS Code

I'm excited to announce the public preview of GitHub Copilot for Azure - a new addition to your toolkit that seamlessly integrates with G...

1 year ago

Build Intelligent Apps Code-First with Prompty and Azure AI

      Building Generative AI applications can feel daunting for traditional app developers. What does the end-to-end applicati...

1 year ago

Certificación AI-900 (Fundamentos de IA) con Chicas en IA

La inteligencia artificial ha llegado para quedarse, ¡y más aún con la revolucionaria IA generativa! Para ayudar a los profesionales a especia...

1 year ago

Get certified with Learn Live GitHub series!

GitHub Universe is coming, and Microsoft and GitHub are partnering to offer a new special Learn Live series in Brazilian Portuguese, English a...

1 year ago

Certifícate con Learn Live GitHub en Español

Microsoft y GitHub se han unido para ofrecer una nueva serie especial de Learn Live en inglés y español: GitHub 2024. Del 10 al 24 de Octubre,...

1 year ago

Evaluating generative AI: Best practices for developers

As a developer working with generative AI, you've likely marveled at the impressive outputs your models can produce. But how do you ensure the...

1 year ago

Introducing Azure Product Retirement Livestreams

The Azure Retirements team, in collaboration with key partner groups, is excited t...

1 year ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.