如何在C#Console App中返回一个简单的int值(How to return a simple int value in C# Console App)

好的,所以我在这个网站上找不到任何补救措施,大约三天前开始编程,我正在完成这本书。 我正在自己练习方法我无法使用我的int方法在Main方法中返回一个简单表达式的乘积。

这是我的代码:

static void Main(string[] args) { Console.WriteLine(test(5, 5)); } static int test(int num1, int num2) { int hold = num1 * num2; Console.ReadLine(); return hold; } } }

关于这个主题的任何额外信息将不胜感激。 谢谢。 我确定这是最终用户逻辑错误。

OK, so I couldn't find anything as remedial on this website, started programming about three days ago and i'm working through this book. I'm practicing methods on my own I cannot get my int method to return the product of a simple expression in my Main method.

Here is my code:

static void Main(string[] args) { Console.WriteLine(test(5, 5)); } static int test(int num1, int num2) { int hold = num1 * num2; Console.ReadLine(); return hold; } } }

Any extra info would on this topic would be greatly appreciated. Thank you. I'm certain it is an end user logic error.

最满意答案

尝试这个:

Console.ReadLine()用于从键盘获取输入

static void Main(string[] args) { Console.WriteLine(test(5, 5)); Console.ReadLine(); } static int test(int num1, int num2) { int hold = num1 * num2; return hold; } } }

try this:

Console.ReadLine() is used to get Input from Keyboard

static void Main(string[] args) { Console.WriteLine(test(5, 5)); Console.ReadLine(); } static int test(int num1, int num2) { int hold = num1 * num2; return hold; } } }

更多推荐