【问题标题】:Printing numbers from 1 to 1000 in console application in C#在 C# 的控制台应用程序中打印从 1 到 1000 的数字
【发布时间】:2017-02-10 05:52:13
【问题描述】:

问题是它只打印从 702 到 1000。从 1 到 1000 打印数字的代码应该是什么。

static void Main(string[] args)
        {
            //    Console.Write("\tOutput : " + arr[0] + arr[1] + arr[2] + arr[3] + "\n");
            //int[] arr = new int[4] { 0, 0, 0, 0 };


            for (int i=0; i<=1000; i++)
            {
                Console.WriteLine(i);
            }
            Console.ReadKey();
        }

【问题讨论】:

标签: c# visual-studio loops console-application


【解决方案1】:

您只能看到最后 300 行左右,因为您的控制台窗口有一个 limited line buffer。

您的代码很好(除了它还打印 0),当您增加行缓冲区大小或将标准输出重定向到如下文件时,您会看到:

myprogram.exe &gt; output.log

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-03
    • 1970-01-01
    • 1970-01-01
    • 2010-11-25
    相关资源
    最近更新 更多