[英]Why on the first pic code doen't execute, but on the second it does?
Exactly i know how to solve this problem, but i don't understand why this solution works.我确实知道如何解决这个问题,但我不明白为什么这个解决方案有效。
I mean what the first( 1 ) piece of code dosn't output anything, but the second(2) works correctly.我的意思是第一(1)段代码不输出任何内容,但第二(2)段工作正常。
I need an explanation - why.我需要一个解释——为什么。
(1). (1).
class Greetings
{
static void Main(string[] args)
{
cube(5);
Console.ReadKey();
}
static int cube(int num)
{
int result = num * num;
return result;
}
}
(2). (2).
class Greetings
{
static void Main(string[] args)
{
Console.WriteLine(cube(5));
Console.ReadKey();
}
static int cube(int num)
{
int result = num * num * num;
return result;
}
}
It has to output 125, but it doesn't output anything.它必须输出 125,但它不输出任何内容。
Because you don't print the answer with the Console.WriteLine();
因为你没有用
Console.WriteLine();
打印答案Console.WriteLine();
method in the first piece of code.第一段代码中的方法。 The result is returned but not printed to the console, because there is no
Console.WriteLine();
结果返回但不打印到控制台,因为没有
Console.WriteLine();
. .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.