简体   繁体   English

为什么在第一个图片代码不执行,但在第二个呢?

[英]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.

相关问题 我的代码第一次不执行? 为什么? - my code does not execute the at first time? why? 为什么第二个for循环总是比第一个循环执行得快? - Why does the second for loop always execute faster than the first one? 统一粒子不会第二次播放 - unity particle doen't play second time 为什么这不起作用? 不执行代码? - Why is this not working? Does not execute code? 为什么动态在第一种情况下有效,而在第二种情况下无效? - Why does dynamic work in the first case but not in the second? 为什么这段代码只在我选择更多1时保存第一张图片 - why this code only save first pic while i am selection more the 1 为什么 finally 块中的代码不执行? - Why code in finally block doesn't execute? 为什么Main(string [] args)函数总是先执行,即在代码中出现的任何其他函数之前执行 - Why does the Main(string[] args) function always execute first , ie., before any other function present in the code 为什么第一个代码会立即显示错误消息,但第二个代码不会 - Why the first code displays error message immediately, but second not 为什么更新第一个变量值时第二个变量值会改变? - Why does my second variable value change when updating the first?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM