如何在Visual Studio中的一个项目中运行多个C#程序

huangapple go评论53阅读模式
英文:

How to run multiple c# programs in one project in Visual Studio

问题

I'm new to programming and visual studio. I'm just starting with c# in VS. I want to run multiple programs one by one, I wrote two programs and when I try to run them I think the entire project is running but I can see the output of only the first program, not the others. When I try to put one file as startup it's not allowing me to:

如何在Visual Studio中的一个项目中运行多个C#程序

如何在Visual Studio中的一个项目中运行多个C#程序

如何在Visual Studio中的一个项目中运行多个C#程序

如何在Visual Studio中的一个项目中运行多个C#程序

如何在Visual Studio中的一个项目中运行多个C#程序

如何在Visual Studio中的一个项目中运行多个C#程序

Thanks in advance.

英文:

I'm new to programming and visual studio. I'm just starting with c# in VS. I want to run multiple programs one by one, I wrote two programs and when I try to run them I think the entire project is running but I can see the output of only the first program, not the others. When I try to put one file as startup it's not allowing me to:

如何在Visual Studio中的一个项目中运行多个C#程序

如何在Visual Studio中的一个项目中运行多个C#程序

如何在Visual Studio中的一个项目中运行多个C#程序

如何在Visual Studio中的一个项目中运行多个C#程序

如何在Visual Studio中的一个项目中运行多个C#程序

如何在Visual Studio中的一个项目中运行多个C#程序

Thanks in advance.

答案1

得分: 1

我认为你在一开始的思考上存在问题。例如,如果你想运行两个不同的代码块以实现不同的操作,就不应该期望主方法能帮助你,因为通常一个项目只能有一个入口。也许因为你是新手,你可能不知道在C#中有一种基本操作,可以将独立的操作编写成一个方法。如果这不是你想要的,请告诉我。例如,你提供的代码可以这样写:

namespace testProject
{
    class prj2
    {
        public void test()
        {
            Console.WriteLine("Hello");
        }
    }
}

然后在程序中添加上述方法,操作如下:

using testProject;

Console.WriteLine("Hello, World!");

prj2 prj2 = new prj2();
prj2.test();

这样,两个段落可以同时输出。

有关详细信息,你可以参考:https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods

英文:

I think there is a problem with your thinking at the beginning. For example, if you want to run two different code blocks to achieve different operations, you should not expect the main method to help you, because usually a project can only have one entry. Maybe because you are a novice, you may not know that there is a basic operation in C# that writes an independent operation as a method. If this is not what you want, please let me know. For example, the code you provided can be written like this:

namespace testProject
{
     class prj2
     {
         public void test()
         {
             Console. WriteLine("Hello");
         }
     }
}

Then add the above method in the program, the operation is as follows:

using testProject;
 
Console. WriteLine("Hello, World!");
 
prj2 prj2= new prj2();
prj2.test();

In this way, two paragraphs can be output at the same time:

For details, you can refer to: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods

答案2

得分: 0

你必须创建两个不同的项目,才能在Visual Studio中同时运行它们。一旦在同一个解决方案中创建了两个项目,请查看此处的文档

英文:

You must create two different projects to be able to run both at same time in Visual Studio. Once you have created two projects in the same solution take a look at the documentation here

huangapple
  • 本文由 发表于 2023年5月21日 00:56:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296364.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定