0

I started a course about C#, but when I tried to run the code there was no button, just a button named attach.

I searched online and have found no clue on how to solve this problem.

The Button

I was expecting to run my code in the Visual Studio Community.

LW001
  • 2,452
  • 6
  • 27
  • 36
  • 1
    You're editing a standalone file. You need to create a Project first. – Dai Aug 21 '23 at 23:50
  • Here are some [tutorials](https://learn.microsoft.com/en-us/shows/csharp-fundamentals-for-absolute-beginners/) to get you going. And here's the tutorial that will help you understand Dai's comment, [Working with Code Files, Projects, and Solutions](https://learn.microsoft.com/en-us/shows/csharp-fundamentals-for-absolute-beginners/working-with-code-files-projects-and-solutions). All the best in your adventures :) – quaabaam Aug 22 '23 at 00:27
  • The problem is that it is what shows when i create a Project :/ – Verozian Aug 22 '23 at 01:11
  • Click `Toolbar -> View -> Solution Explorer`. Is there a solution ConsoleApp1? – Minxin Yu - MSFT Aug 22 '23 at 02:15
  • Also, please check the environment variable is set: https://stackoverflow.com/questions/67049414/windows-or-visual-studio-2022-cant-find-the-latest-installed-net-sdk-due-to-bi/67049415#67049415 – Minxin Yu - MSFT Aug 25 '23 at 06:15

1 Answers1

-1

You can execute the code using the C# interactive window if you just want to execute C# code with no project.

  1. Highlight the code you want to run
  2. Right click and select- "Execute in C# Interactive"

To get the buttons you are asking about then you need to add your .CS file to a project. The easiest solution is to create a new project with the option to use existing files. Microsoft link : Create a project from existing code files Project from Existing Code

You are using top-level statements. See link with explanation of this style vs a "Program.Main" type style program. A lot of examples will use the Program.Main style C# console app template generates top-level statements

If you receive an error like :

Error CS8370 Feature 'top-level statements' is not available in C# 7.3. Please use language version 9.0 or greater.

  1. Right click and select quick actions
  2. Select Convert to Program.Main style

Convert to Program.Main style

SoftwareCarpenter
  • 3,835
  • 3
  • 25
  • 37