The process of installing, configuring, and customizing Visual Studio to support development workflows across languages, platforms, and workloads.
Thank you for reaching out.
This happens because Visual Studio always runs the project, not the file you just open on the screen.
When you create a new C# project, Visual Studio automatically creates a project that already contains a Program.cs file with Hello World code. That file becomes the project’s entry point. Visual Studio will always build and run that file unless the project itself is changed.
If you later open another Program.cs from a folder, Visual Studio only opens it for viewing. That file is not part of the project, so it is ignored when you build and run. Even if that file is visible or active in the editor, Visual Studio still runs the original Hello World program because it belongs to the project.
This behavior does not happen every time you open Visual Studio. It happens when a new project is created, because the Hello World code is added once as part of the project template. After that, Visual Studio simply keeps running the project’s entry point.
Reference:
explains that when a new C# console project is created, Visual Studio opens a project that already includes default Hello World code in Program.cs, and that file is what runs when you start the app: https://learn.microsoft.com/en-us/visualstudio/get-started/csharp/tutorial-console?view=visualstudio
Please let us know if you require any further assistance, we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer". So that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.