c# - 使用两个 for 循环

标签 c# for-loop

这是一个简单的问题,但我仍在学习这门语言。

我们如何编写具有参数的程序,以便如果数字为 5,它将写入

*
**
***
****
*****

我能做到:

*
*
*
*

使用这个:

private void button1_Click(object sender, EventArgs e)
{
    string message = " ";

    for (int count = 0; count < numericUpDown1.Value; count++)
    {
        for (int m = 0; m < numericUpDown1.Value; count)
        {
            message += "*" + "\r\n";
        }
    }
}

我想我需要第二个 for 循环,但我不确定下一步该做什么。

最佳答案

如果这不是概念性作业,那么用这种方式解决会容易得多:

for(int i=1; i<=n; i++)
  Console.WriteLine(new string('*',i));

关于c# - 使用两个 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11630081/

相关文章:

r - 在 R 中如何检查序列是否为 'almost increasing sequence'?

python - 我的变量在循环内部或外部发生变化

c# - 如何将字符串列排序为 GridView 中的日期时间列

c# - 如何使 protobuf-net 在反序列化时不考虑默认数组值

bash - 使用 find lacks 的循环无法正确处理具有空格字符的目录名称

c - 为什么在我的代码中第二个 "for"在函数循环中只有一次

c# - 业务逻辑层设计

c# - 通过 asp.net 向多个用户发送邮件

c# - 并发字典 : How do I add if value does not exist or condition fails?

c - 如何在 C 中将 double 组转换为整数数组?