简体   繁体   English

C#中的Euler项目#4

[英]Project Euler #4 in C#

I'm attempting to do Project Euler problem #4 in C#. 我正在尝试在C#中执行Project Euler问题#4。 The problem I'm having is that when the code runs a console window briefly appears and then goes away. 我遇到的问题是,当代码运行时,控制台窗口会短暂出现然后消失。 I don't know what the problem could be as I'm relatively new to programming. 我不知道问题可能出在什么地方,因为我是编程的新手。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1000; i > 100; i--)
                for (int j = 1000; j > 100; j--)
                    PalCheck(i * j);
        }

        static void PalCheck(int original)
        {
            var reversed = new string(Convert.ToString(original).ToCharArray().Reverse().ToArray());

            if (Convert.ToString(original) == reversed)
                Console.WriteLine(original);

            Console.ReadKey();
        }
    }
}

The code seems to be stuck at the line Console.ReadKey() as at this line of code, the program is waiting for some input key. 该代码似乎停留在Console.ReadKey()行中,因为在此代码行中,程序正在等待某些输入键。 Since you have not used any message before ReadKey(), you don't realize that the program is waiting for some input and not stuck. 由于您在ReadKey()之前没有使用任何消息,因此您不会意识到程序正在等待某些输入并且不会卡住。

Move Console.ReadKey() after PalCheck(i * j) and you should see the output on the console screen. 将Console.ReadKey()移至PalCheck(i * j)之后,您应该在控制台屏幕上看到输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM