#GitHubCopilot 🤖 – General experience with C#, generating unit tests, security keys and more.

Hi !

I used mostly Copilot with Python, and I have to admit that it generates super accurate Machine Learning and TensorFlow code. I don’t to a lot of C# code in Visual Studio Code, I’m old school I use Visual Studio 2022 for C#. However, I decided to give it a try and here are the results.

General Experience

Let’s start with the Hello World in CoPilot, let’s add 2 numbers.

copilot generating code to add two numbers in csharp

It works great, let’s generate a more complex scenario.

copilot generating code to add two numbers with an condition in csharp

So far, so good!

Copilot and Code Block suggestions in C#

However, in the previous animations you can see that CoPilot behavior is different in C#, it suggest line by line, not a code block.

There is an easy hack for this, instead of accepting each line, we can open the CoPilot editor with the shortcut CTRL + ENTER and we can check the top 10 CoPilot code suggestions. From there we can add the C# code block to our code.

copilot generating code to add two numbers in csharp from copilot code editor suggestions

Generating Unit Tests

How about Unit Tests ? I know that it’s will generate some code, and I was wondering what it will do. This is a simple CS file, it does not belong to a C# project, so there are no references to any Unit Test framework. The output is awesome.

As you can see in the animation below, from the code editor suggestions, some options does not makes sense, however there are 2 that really nails and test a simple Add() function !

copilot cs generate unit test

Generating Connection Strings or Azure Keys

And I leave this one to the end, how about connection strings? CoPilot was trained on public code, and I’m sure that there are no connection strings or azure keys in GitHub. The generated output is great, I’ll leave it to you to think about this.

copilot cs generate azure key

That’s it’s for today. Remember that you can take a look at the 75 min review (in Spanish) that we did with my friends from CampusMVP here.

GitHubCopilot 🤖: qué es, cómo funciona y el impacto futuro de la IA en el trabajo de programador. Grabación 

Happy coding!

Greetings

El Bruno



¿Con ganas de ponerte al día?

En Lemoncode te ofrecemos formación online impartida por profesionales que se baten el cobre en consultoría:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.