{"id":248626,"date":"2024-04-16T03:00:38","date_gmt":"2024-04-16T10:00:38","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=248626"},"modified":"2024-05-15T12:05:30","modified_gmt":"2024-05-15T19:05:30","slug":"how-to-use-github-copilot-chat-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/how-to-use-github-copilot-chat-in-visual-studio\/","title":{"rendered":"How to use GitHub Copilot Chat in Visual Studio"},"content":{"rendered":"<p>In this series, we will explore the capabilities and how to use GitHub Copilot Chat within Visual Studio, demonstrating how it can elevate your coding efficiency. GitHub Copilot serves as an AI-powered coding assistant designed to enhance your coding experience across various development environments.<\/p>\n<h2><strong>Exploring code with GitHub Copilot Chat<\/strong><\/h2>\n<p>In our latest video, my colleague Bruno Capuano showcases the utility of GitHub Copilot Chat within Visual Studio, specifically focusing on populating arrays with random numbers. While arrays are a fundamental data structure, GitHub Copilot Chat facilitates exploration beyond arrays, guiding users towards utilizing more versatile structures like Lists.<\/p>\n<p><em>Make sure to have GitHub Copilot installed, refer to the documentation to learn <a href=\"https:\/\/learn.microsoft.com\/visualstudio\/ide\/visual-studio-github-copilot-chat?view=vs-2022#install-the-visual-studio-extension\/?WT.mc_id=academic-129246-lbugnion\">how to install GitHub Copilot Chat for Visual Studio.<\/a><\/em><\/p>\n<p><iframe title=\"Using GitHub Copilot Chat in Visual Studio\" src=\"\/\/www.youtube.com\/embed\/v4Jw9uQyQUQ?feature=oembed\" width=\"560\" height=\"314\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>GitHub Copilot Chat streamlines the understanding of differences between arrays and Lists, highlighting key distinctions such as:<\/p>\n<ul>\n<li><strong>Size:<\/strong> Arrays have a fixed-size structure, whereas Lists can dynamically adjust their size during runtime.<\/li>\n<li><strong>Performance:<\/strong> Arrays generally offer higher efficiency due to their static sizing, while Lists excel in scenarios requiring frequent size adjustments.<\/li>\n<li><strong>Functionality:<\/strong> Lists boast a broader array of methods compared to arrays, enabling more versatile data manipulation.<\/li>\n<\/ul>\n<p>Additionally, GitHub Copilot Chat offers code examples demonstrating the creation of arrays and Lists, alongside basic element addition operations.<\/p>\n<p>You need not explicitly specify the programming language or framework to GitHub Copilot Chat; it intuitively adapts to the context of your solution and file, mimicking the natural flow of communication during pair-programming sessions.<\/p>\n<h3><strong>Converting code<\/strong><\/h3>\n<p>In a practical demonstration, Bruno utilizes GitHub Copilot Chat to seamlessly transition code initially utilizing arrays into more flexible List-based implementations. Notably, the preview feature provides a comprehensive overview of proposed code modifications, empowering users to validate Copilot-generated solutions before implementation.<\/p>\n<p>I&#8217;ve replicated Bruno&#8217;s example below, showcasing the code suggested by Copilot Chat both before and after the conversion:<\/p>\n<p><strong>Before<\/strong><\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\"><strong>\/\/ fill an array with 10 random numbers\r\nint[] numbers = new int[10];\r\nRandom random = new Random();\r\nfor (int i = 0; i &lt; numbers.Length; i++)\r\n{\r\n    numbers[i] = random.Next(1, 100);\r\n}<\/strong>\r\n<\/code><code class=\"language-cs language-csharp\">\r\n<\/code><\/pre>\n<p>When selecting the code and opening the GitHub Copilot chat dialogue window, we&#8217;ll ask Copilot to convert the code to use the list format.<\/p>\n<p><figure id=\"attachment_248628\" aria-labelledby=\"figcaption_attachment_248628\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-1.png\"><img decoding=\"async\" class=\"wp-image-248628 size-large\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-1-1024x454.png\" alt=\"Asking Copilot to convert the code\" width=\"640\" height=\"284\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-1-1024x454.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-1-300x133.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-1-768x340.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-1.png 1426w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><figcaption id=\"figcaption_attachment_248628\" class=\"wp-caption-text\"><strong>Asking Copilot to convert the code<\/strong><\/figcaption><\/figure><\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\"><\/code><\/pre>\n<p><strong>After<\/strong><\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><strong><code class=\"language-cs language-csharp\">\/\/ fill a list with 10 random numbers\r\nList&lt;int&gt; numbers = new List&lt;int&gt;();\r\nRandom random = new Random();\r\nfor (int i = 0; i &lt; 10; i++)\r\n{\r\n    numbers.Add(random.Next(1, 100));\r\n}<\/code><\/strong><\/pre>\n<p><figure id=\"attachment_248630\" aria-labelledby=\"figcaption_attachment_248630\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-2.png\"><img decoding=\"async\" class=\"wp-image-248630 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-2.png\" alt=\"The proposed solution\" width=\"693\" height=\"945\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-2.png 693w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-2-220x300.png 220w\" sizes=\"(max-width: 693px) 100vw, 693px\" \/><\/a><figcaption id=\"figcaption_attachment_248630\" class=\"wp-caption-text\"><strong>The proposed solution<\/strong><\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_248631\" aria-labelledby=\"figcaption_attachment_248631\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-3.png\"><img decoding=\"async\" class=\"wp-image-248631 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-3.png\" alt=\"The Preview feature\" width=\"1320\" height=\"460\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-3.png 1320w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-3-300x105.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-3-1024x357.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/laurent-3-768x268.png 768w\" sizes=\"(max-width: 1320px) 100vw, 1320px\" \/><\/a><figcaption id=\"figcaption_attachment_248631\" class=\"wp-caption-text\"><strong>The Preview feature<\/strong><\/figcaption><\/figure><\/p>\n<div class=\"mceTemp\"><\/div>\n<h3><strong>Conclusion<\/strong><\/h3>\n<p>Now that you have successfully installed GitHub Copilot in Visual Studio, you can now enjoy the benefits of AI-powered coding assistance. GitHub Copilot can help you write code faster and you can also learn from the suggestions and examples that GitHub Copilot provides. To learn more about GitHub Copilot and how to use it, <a href=\"https:\/\/learn.microsoft.com\/collections\/ng58uwrk6g53ox?WT.mc_id=academic-129245-abartolo\" target=\"_blank\" rel=\"noopener\">check our collection with resources here<\/a>\u00a0or via our\u00a0<a href=\"https:\/\/youtu.be\/z1ycDvspv8U\" target=\"_blank\" rel=\"noopener\">full-length video<\/a>.<\/p>\n<h4><strong>Additional Resources<\/strong><\/h4>\n<ul>\n<li><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/copilot-chat-slash-commands-and-context-variables\/\" target=\"_blank\" rel=\"noopener\">Code Faster and Better with GitHub Copilot\u2019s New Features: Slash Commands and Context Variables<\/a><\/li>\n<li><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/announcing-the-github-extension-for-visual-studio\/\" target=\"_blank\" rel=\"noopener\">Announcing the GitHub Extension for Visual Studio<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this series, we will explore the capabilities and how to use GitHub Copilot Chat within Visual Studio, demonstrating how it can elevate your coding efficiency. GitHub Copilot serves as an AI-powered coding assistant designed to enhance your coding experience across various development environments. Exploring code with GitHub Copilot Chat In our latest video, my [&hellip;]<\/p>\n","protected":false},"author":24687,"featured_media":248898,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[6887,6888,6941,1388,6904,155],"tags":[1055,6946,4381,6924,6906,6944,287,12],"class_list":["post-248626","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence","category-copilot","category-copilot-2024-series","category-extensibility","category-installation-and-updates","category-visual-studio","tag-ai","tag-cynthia-zanoni","tag-github","tag-github-copilot","tag-install","tag-laurent-bugnion","tag-tips-and-tricks","tag-visual-studio"],"acf":[],"blog_post_summary":"<p>In this series, we will explore the capabilities and how to use GitHub Copilot Chat within Visual Studio, demonstrating how it can elevate your coding efficiency. GitHub Copilot serves as an AI-powered coding assistant designed to enhance your coding experience across various development environments. Exploring code with GitHub Copilot Chat In our latest video, my [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/248626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/24687"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=248626"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/248626\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/248898"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=248626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=248626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=248626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}