为什么C#程序运行较慢而没有调试

时间:2015-01-11 21:20:51

标签: c# visual-studio-2013

我有一个简短的程序可以打印10到999,999之间的所有阿姆斯壮数字。

当我在调试模式下运行时,它会在1秒内完成。

当我在没有调试的情况下运行时,会打开两个命令窗口。当第二个最终关闭时,输出显示在第一个上(这大约需要12秒)。但是,如果我从任务管理器中删除第二个窗口;完整输出显示在第一个窗口中。

此外,运行直接.exe文件会导致与没有调试时运行相同的行为。

此外:当我运行直接的exe文件时,我得到大约100 MB的RAM使用率(据我所知,我不应该为这么小的程序)。

这是我的代码:

using System;
public class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine("ARMSTRONG NUMBERS FOUND FROM 10 THROUGH 999999\n");
        int total_armstrong = 0;
        for (int i = 10; i < 1000000; i++)
        {
            int temp = i;
            int k;
            int total = 0;

            for (k = 0; temp != 0; k++) //runs only 6 times maximum    gives me the exponent to use below
                temp /= 10;
            temp = i;
            while (temp != 0) //runs only 6 times maximum
            {
                total += (int)Math.Pow(temp % 10, k);  //calculates the value of each digit raised to the exponent calculated above
                temp /= 10;
            }
            if (total == i)
            {
                Console.WriteLine(total);
                total_armstrong++;
            }
        }
        Console.WriteLine("\nTOTAL NUMBER OF ARMSTRONG NUMBERS FOUND WAS " + total_armstrong);
    }
}

运行时的外观图像: 右侧关闭后,输出显示在左侧窗口中

image in question

enter image description here

1 个答案:

答案 0 :(得分:0)

我最终重新安装了Visual Studio / Windows,问题解决了。最终核选项总能解决问题。

相关问题