Write the following code using c #, Write a method similar to the one above that displays a vertical line of stars. Call this method three times with arguments 0, 5 and 10 respectively.
时间: 2024-02-13 21:01:59 浏览: 85
Sure, here's the code in C#:
```csharp
using System;
class Program
{
static void Main(string[] args)
{
DrawVerticalLineOfStars(0);
DrawVerticalLineOfStars(5);
DrawVerticalLineOfStars(10);
}
static void DrawVerticalLineOfStars(int length)
{
for (int i = 0; i < length; i++)
{
Console.WriteLine("*");
}
Console.WriteLine();
}
}
```
This code defines a `DrawVerticalLineOfStars` method that takes an integer argument `length` and uses a `for` loop to print out `length` number of `*` characters on separate lines. The `Main` method then calls this method three times with arguments of 0, 5, and 10, respectively, to display vertical lines of stars of different lengths.
阅读全文