0
我需要在控制台中编写代码,它会使行的编号出现在它自己的行上,也显示在行上的位置。我的程序只输出一行*****,我似乎无法让它更多。帮助将提前用迭代解决C#
eg 1*****
*2****
**3***
***4**
我现在有惊人的感谢堆,
static void Main(string[] args)
{
int n = 0;
string s = "";
//check if 2 args
if (args.Length == 2)
{
if (int.TryParse(args[0], out n))
{
//successful parse, so use n
s = args[1]; //second argument is character
//draw a line of characters
DrawChars(n, s);
}
else
{
//unsuccessful parse, so no n value
}
}
//wait for user to have read output
Console.WriteLine();
Console.Write("Press enter to finish:");
Console.ReadLine();
}
/// <summary>
/// Method to draw a line of characters
/// </summary>
/// <param name="n">number of characters to draw</param>
/// <param name="s">character to draw n times</param>
static void DrawChars(int n, string s)
{
for (int i = 1; i <= n; i++)
{
Console.Write(s);
}
Console.WriteLine();
}
S = “” 不 “d” 和IVe的集合n为0 – nzimpossible