So zeigen Sie eine einfache hohle Sternchen Rechteck in der Konsole?

Könnte jemand mir raten, auf eine einfache Art und Weise zu implementieren hohlen Rechtecken in C#?

Ich in der Lage gewesen, ein einfaches Rechteck, sondern hohl Rechteck-Programme habe ich mir angeschaut entweder enthalten oder arrays oder waren ziemlich verworren. Zum Beispiel, die Lösung auf ein anderes forum das scheint zu anspruchsvoll, und diese Antwort auf CodeReview.SE ist zu schwer zu verstehen.

Dies ist, was ich getan habe, das zeigt eine einfache (gefülltes) Rechteck. , Wie die Ausgabe eines hohlen Rechtecks if Logik, wenn möglich?

class Nested_Loops_Hollow_Rectangles
{
    public void RunExercise()
    {
        //how are now supposed to make this hollow?
        //columns are side by side, rows is number of top to bottom
        //see tut
        Console.WriteLine("Welcome to the HollowRectanglePrinter Program.");
        Console.WriteLine("How many columns wide should the rectangle be?"); //i.e. 4
        int iColMax, iRowMax;
        string userChoiceC = Console.ReadLine();
        Int32.TryParse(userChoiceC, out iColMax);
        Console.WriteLine("How many rows tall should the rectangle be?  "); //i.e. 4
        string userChoiceR = Console.ReadLine();
        Int32.TryParse(userChoiceR, out iRowMax);
        Console.WriteLine("Here you go:");

        if (iRowMax > 0 || iColMax > 0) 
        {
            for (int iRow = 0; iRow < iRowMax; iRow++) 
            {
                for (int iCol = 0; iCol < iColMax; iCol++) 
                {
                    Console.Write("*");
                }

                Console.WriteLine();
            }
        }
    }
}
InformationsquelleAutor cinnamon | 2015-02-08
Schreibe einen Kommentar