如何编译和运行单个类文件CS文件? [英] How to compile and run a single class file cs file?

查看:181
本文介绍了如何编译和运行单个类文件CS文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这很简单,我是Visual Studio的新手,我有一个项目,其中包含多个类文件(.cs)文件,如何分别运行每个文件.每当我调试时,它只会选择一个.cs文件.谢谢.

Sorry if this is trivial, I am new to Visual Studio, I have a single project in which contains multiple class files (.cs) files, how do I run each one individually. Whenever I go to debug, it selects only a single .cs file. Thanks.

来自使用netbeans的Java背景,可以提供一个包中包含多个.java文件的包,条件是每个.java文件都有一个主要方法,可以分别编译和运行它们.这样的东西在Visual Studio中可用吗?

Edit : Coming from a java background using netbeans, it is possible to have a package with several .java files in the package, provided each of the .java files have a main method they can be individually compiled and ran. Is something like this available in Visual Studio?

推荐答案

如果要选择运行哪个Main方法,可以在Startup Object下的Project -> Properties中进行选择.有许多需要满足的要求(例如静态的),并且一次只能选择一个.

If you want to select which Main method gets run, you can select that in Project -> Properties under Startup Object. There are various requirements that need to be met (like being static) and you can only select one at a time.

如果要在多个静态类上调用main方法,则需要创建一个主方法来调用其他方法.您可能会变得很复杂,并使用反射来在您的项目中搜索这些类,但这比静态地调用它们要复杂得多.

If you want to call the main method on multiple static classes, you'll need to create a main one that calls the other ones. You could get complicated and use reflection to search your project for the classes, but it's much more work than just statically calling them.

这篇关于如何编译和运行单个类文件CS文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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