问题描述
我一般对编程还很陌生,所以我确定这个问题很幼稚。
I'm very new to programming in general so I'm sure this question is naive.
所以,我写了一个简单的魔术八球程序,我想进入冒险游戏,但我认为在游戏中包含八个球程序会很整洁,例如制作一个控制台菜单,您可以在其中选择任何一款游戏。
So, I wrote a simple magic eight ball program and I wanted to move onto an adventure game, but I thought it would be neat to include the eight ball program in the game, like making a console menu where you could select either game.
所以,我的问题是,我不知道如何将我的Augustball程序放入文件中,然后使用类似的东西从主程序文件运行它
So, my problem is, I don't know how to put my eightball program in a file, and then run it from the main program file with something like
eightball();
如果可以简单地做到这一点,我是否也可以在if语句中使用它,例如
And if this can be done simply, could I also use it in an if statement, like
if (response == 1)
{
eightball();
}
谢谢大家的帮助!
我敢肯定我在研究中遇到了问题,但是我可能不理解。
Also I'm sure I ran across the answer in my research, however I probably didn't understand it.
推荐答案
看看。
您可能想要创建一个新的 class文件,然后添加如下代码:
You will probably want to create a new class file and then add your code something like this:
namespace MyApplication
{
class EightBall
{
public static void eightball ()
{
// Add your code here
}
}
}
从您的 Main
函数是这样的:
if (response == 1)
{
EightBall.eightball();
}
这篇关于在主program.cs文件中运行另一个.cs文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!