C# 如何使用C中的do while循环生成模式#

C# 如何使用C中的do while循环生成模式#,c#,do-while,do-loops,C#,Do While,Do Loops,说到循环,我算是个新手( 请帮帮我 问题: 使用do循环,绘制以下图案: class类main类 { 公共静态void Main(字符串[]args) { int计数器=1; 做{ 对于(int i=0;i

说到循环,我算是个新手( 请帮帮我

问题:

使用
do
循环,绘制以下图案:

class类main类
{
公共静态void Main(字符串[]args)
{
int计数器=1;
做{
对于(int i=0;i
对不起,我的英语不好。
您可以在do while循环中使用计数器

您可以创建一个生成星号字符串的方法:

public static string starGenerator(int count)
{
    string stars = string.Empty;
    for(int i = 0; i < count; i++)
        stars += "*";

    return stars;
}
publicstaticstringstargenerator(int计数)
{
string stars=string.Empty;
for(int i=0;i
然后使用它:

public static void Main(string[] args)
{
    int counter = 1;
    do
    {
        string stars = starGenerator(counter);
        Console.WriteLine(stars);

        counter++;
    } while(counter <= 5);
}
publicstaticvoidmain(字符串[]args)
{
int计数器=1;
做
{
串星=星发生器(计数器);
控制台。WriteLine(星星);
计数器++;

}while(counter如果您坚持
do..while
,有很多方法可以实现这一点:

string line = "";

do {
  Console.WriteLine(line += "*");
}
while (line.Length < 6);
字符串行=”;
做{
Console.WriteLine(第+=“*”)行;
}
而(直线长度<6);

这看起来像是学校的作业,你自己尝试过什么吗?只需使用两个嵌套的do循环进行尝试,不要等待答案。这不是一个教程网站。阅读并学习这很容易。我实际上使用AddRange()方法提示做了这件事。在谷歌上搜索如何使用它。。
public static void Main(string[] args)
{
    int counter = 1;
    do
    {
        string stars = starGenerator(counter);
        Console.WriteLine(stars);

        counter++;
    } while(counter <= 5);
}
string line = "";

do {
  Console.WriteLine(line += "*");
}
while (line.Length < 6);