在C#中打印0000到9999的所有组合

The*_* IT 0 c# printing

只是想知道是否有人有一个算法躺在那里打印从0000到9999的所有可能的组合(试图破解代码到旧手机和新的学习C#)...百万谢谢.贝拉

ang*_*son 25

为什么复杂的事情?

for (Int32 index = 0; index < 10000; index++)
    Console.Out.WriteLine(index.ToString("0000"));
Run Code Online (Sandbox Code Playgroud)

由于您正在评论您输出的是标签,并且每个值之间都有换行符,因此这是一种更好的方法:

List<String> values = new List<String>();
for (Int32 index = 0; index < 10000; index++)
    values.Add(index.ToString("0000"));
label1.Text = String.Join(
    Environment.NewLine,
    values.ToArray());
Run Code Online (Sandbox Code Playgroud)

尝试一下,看看它是否能满足您的需求.


Gra*_*ton 10

WTF参赛作品:

Console.WriteLine("0000"); 
Console.WriteLine("0001"); 
Console.WriteLine("0002"); 
Console.WriteLine("0003"); 

// snip everything in the middle

Console.WriteLine("9998"); 
Console.WriteLine("9999"); 
Run Code Online (Sandbox Code Playgroud)

对于那些缺乏幽默感的人,不要在家里试试.

  • 一个值得质疑的答案. (2认同)
  • 请注意,对于完整的WTF答案,您应该在这里发布所有这些行(您将获得代码字段的滚动条),但随后省略一个随机行,仅用于踢. (2认同)