C# 是否有一个和函数可以用许多符号表示为金字塔

C# 是否有一个和函数可以用许多符号表示为金字塔,c#,string,int,C#,String,Int,我想问的是,在命令行中,如何通过字符串中的符号“*”来表示int中的数量,使其看起来像金字塔 例如 int a = int.parse(Console.ReadLine()) a = 1 then Console.WriteLine("*") a = 2 then write"**" 继续3=***4=**** 谢谢我发现最好的方法是使用函数“for”两次,使用函数“new string”。 这将在控制台中创建一个金字塔形状 例如 inta=int.parse(Console.ReadLin

我想问的是,在命令行中,如何通过字符串中的符号“*”来表示int中的数量,使其看起来像金字塔

例如

int a = int.parse(Console.ReadLine())
a = 1 then Console.WriteLine("*")
a = 2 then write"**" 
继续3=***4=****


谢谢

我发现最好的方法是使用函数“for”两次,使用函数“new string”。 这将在控制台中创建一个金字塔形状

例如

inta=int.parse(Console.ReadLine())
对于(int b=0;b0;b--)
{
控制台。写入新字符串('*',c)
Console.WriteLine(“*”)
}

最简单的方法可能就是将给定的次数和concat*循环到一个空的string@haldo对于编程初学者来说很简单。我并不是说你的解决方案不干净,但它肯定不是你在每种编程语言中都能看到的东西。我想问的是,如何用字符串中的符号“*”来表示int值,使其在命令行中看起来像金字塔
int a = int.parse(Console.ReadLine())
For(int b=0;b<a;b++)
{
Console.Write new string('*',b)
Console.WriteLine("*")
}
For(int c=a;b>0;b--)
{
Console.Write new string('*',c)
Console.WriteLine("*")
}