如何在visual studio中的项目下运行不同的类 [英] how to run different classes under a project in visual studio

查看:371
本文介绍了如何在visual studio中的项目下运行不同的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio中有一个C#项目,它下面有几个类。我试图单独运行每个类,但是当我点击启动或调试按钮时,只运行其中一个类(我创建的第一个类)。我试图右键单击其他类但它们没有运行选项。我正在使用Visual Studio Express 2013

I have a C# project in Visual Studio which has several classes under it. I am trying to run each class separately but when ever I hit the start or debug buttons,only one of the classes (the first one I created) runs.I tried right-clicking the other classes but they don't have the run option. I am using Visual Studio Express 2013

推荐答案

您没有在Visual Studio中运行类 - 您运行一个应用程序,并且只能有一个启动项目在解决方案中 - 必须是一个EXE项目(而不是DLL),它将始终在静态Main方法上开始执行(对于WinForms应用程序,您将在program.cs文件中找到它)



单个类不可执行 - 它所包含的各种方法,属性和事件都可以执行,但整个类不是。



除非你以某种方式启动一个新的线程或线程,否则任何时候只能在类方法中执行一个行。因此,如果在每个类构造函数的顶部放置一个断点,那么只有构造的第一个类实例才会首先遇到断点 - 其他人必须等到构造函数完成才能获得机会。



这就像驾驶:你可以拥有六辆不同的汽车,但你只能开车到其中一辆车 - 其他人必须在车库等待直到你回来! :笑:
You don't run a "class" in visual studio - you run an application, and there can only be one "Startup Project" in a solution - that must be an EXE project (rather than a DLL) and it will always start executing at the static Main method (for WinForms applications, you will find it in the "program.cs" file)

Individual classes are not executable - the various methods, properties and events of which it's comprises can be executed, but the class as a whole is not.

And unless you start a new Thread or Threads in some way, only one "line" at a time of your class methods can be executed at any one time. So if you put a breakpoint at the top of each class constructor, only the first class instance constructed will hit a breakpoint first - the others will have to wait until that constructor is finished before they can get a chance.

It's like driving: you can own half a dozen different cars, but you can only drive to the shops in one of them - the others have to wait in the garage until you get back! :laugh:


1.你不能在同一个项目中运行不同的类。



2.但你可以有多个通过使用解决方案资源管理器上下文菜单,应用程序在同一解决方案中的项目,以及设置为启动项目。通过这种方式,您可以启动属于同一解决方案的多个应用程序。
1.You cannot run different classes form the same project.

2.But you can have multiple "application" projects in the same solution, and "Setup as Starting Project" each of them, by using "Solution Explorer" context menu. In this way you can start multiple applications that belong to the same solution.


这篇关于如何在visual studio中的项目下运行不同的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆