How to use GitHub Copilot like a Pro: Part 2
Sourav Bera
Solution Architect @Microsoft, Microsoft Intern FY'22, Judge/Speaker/Mentor, 4 ? CodeChef, Pupil at Codeforces, SIH Winner, SOH Winner, Postman Leader CKA, CKAD, CKS, LFCS IEEE Leadership Summit, Kubestronaut Program
If you are looking for the part 1 series of using GitHub Copilot for Developers here it is: (14) How to use GitHub Copilot: A guide for developers | LinkedIn
Now earlier we learned how to setup GitHub copilot and make basic prompts to get simple code to run on our VS Code. Next we will dive deeper into how we can use the GitHub Copilot in your favorite IDE.
Developing .NET applications can involve repetitive tasks like creating boilerplate code, writing common functionalities, and implementing standard design patterns. GitHub Copilot, an AI code completion tool integrated with Visual Studio Code (VS Code), can significantly streamline this process by suggesting relevant code snippets and entire functions based on your context. This article dives deep into leveraging GitHub Copilot for end-to-end development of a .NET application in VS Code, covering project setup, code generation, running and testing the application.
Prerequisites:
Setting Up the Project:
Generating Code with Copilot:
领英推荐
Example:
// create a stone, paper, scissor game
C#
// create a stone, paper, scissor game
// create a list of options
List<string> options = new List<string>() { "rock", "paper", "scissor" };
// create a random generator
Random random = new Random();
// get a random option from the list
string computerChoice = options[random.Next(0, options.Count)];
// get a user input
Console.WriteLine("Enter your choice: ");
string userChoice = Console.ReadLine();
// check if user choice is valid
if (!options.Contains(userChoice))
{
Console.WriteLine("Invalid choice");
return;
}
Console.WriteLine($"Computer choice: {computerChoice}");
Console.WriteLine($"User choice: {userChoice}");
// check who won
if (computerChoice == userChoice)
{
Console.WriteLine("It's a draw");
}
else if (computerChoice == "rock" && userChoice == "scissor")
{
Console.WriteLine("Computer won");
}
else if (computerChoice == "scissor" && userChoice == "rock")
{
Console.WriteLine("You won");
}
else if (computerChoice == "paper" && userChoice == "rock")
{
Console.WriteLine("Computer won");
}
else if (computerChoice == "rock" && userChoice == "paper")
{
Console.WriteLine("You won");
}
else if (computerChoice == "scissor" && userChoice == "paper")
{
Console.WriteLine("Computer won");
}
else if (computerChoice == "paper" && userChoice == "scissor")
{
Console.WriteLine("You won");
}
Building and Running the Application:
So how cool was it to develop a .net C# Application game from the scratch using GitHub Copilot, no matter we still we had not squander any documentation or youtube video to get the basics done first. Its super easy and cool to get started building your first application using GitHub Copilot. Try around for your next project do ping me the github repository link for me to view, what did you create out of GitHub Copilot.
ASP .NET Core | MAUI | Ex-Data Science trainee at Celebal Technologies | Ex-Database Designer @Dataiku (Remote)
11 个月Very useful Post. Sourav Bera bhaiya