-2

I am trying to run another file in Visual Studio 2019. I have the Program.cs and then Variables.cs which is dedicated to variables. I am following a tutorial.[Here i have 2 files Program.cs and Variables.cs. How can i run Variables.cs. If i try and run it i get an error called "There is already a main entry point". Also for the near future lets say i created a file dedicated o arrays or user input. How can i run user input or arrays? Also how can i also have 2 or more C# files in VSCode without getting a problem when running. I am also a beginner in C#

enter image description here

Carl
  • 1
  • 2
  • Generally there is a "public static void Main()" method in Program.cs that is the start point of the program. If you want something in Variable.cs to execute you need to call it (maybe from Main()) – Kristian Fitzgerald Aug 12 '21 at 00:01
  • How can i call it? Well i know how to call but if Variables is in the same file of Program.cs like variables have its own method called static void Variables(). But how to call from another file? – Carl Aug 12 '21 at 00:02
  • If you post the contents of your 2 files into the question it might be easier to advise – Kristian Fitzgerald Aug 12 '21 at 00:03
  • You cannot "*run*" two files from the same project. You cannot have two `Main` methods in a project. The only thing you can do is create two projects in a solution, run one, and manually start the other while the first is running. You can also configure Visual Studio to run both at the same time. You can also start the same project multiple times as *New Instance*. –  Aug 12 '21 at 04:13
  • Does this answer your question? [Running two projects at once in Visual Studio](https://stackoverflow.com/questions/3850019/running-two-projects-at-once-in-visual-studio) and [Building and running two projects in one solution](https://stackoverflow.com/questions/56097457/building-and-running-two-projects-in-one-solution) and [Is it possible to have more than one main() method in a C# program?](https://stackoverflow.com/questions/17607951/is-it-possible-to-have-more-than-one-main-method-in-a-c-sharp-program) –  Aug 12 '21 at 04:15

1 Answers1

-1

enter image description here

When you right click a different project in your solution, regardless of whether another main() function is already running, you can see a debug option. Mousing over this will allow you to hit Start New Instance, which will run that project simultaneously.

StarshipladDev
  • 1,166
  • 4
  • 17