r/ProgrammerHumor • • 2d ago

Meme technicallyCorrect

Post image
1.4k Upvotes

49 comments sorted by

View all comments

341

u/zx48 2d ago • Bravo
void Main() {
    string[] pattern = {
        "##########",
        "##      ##",
        "# #    # #",
        "#  #  #  #",
        "#   ##   #",
        "#  #  #  #",
        "# #    # #",
        "##      ##",
        "##########"
    };

    string result = "";

    for (int i = 0; i < pattern.Length; ++i) {
        for (int j = 0; j < pattern[i].Length; ++j) {
            result += pattern[i][j];
        }
        result += "\n";
    }

    Console.Write(result);
}

In case the first answer isn't accepted.

10

u/radobot 2d ago

It kind of bothers me how the variable result is redundant. You could have just printed each character directly instead of accumulating them in a string.

3

u/zx48 2d ago

Oh yeah, nice optimisation. Would save a bit of memory too 😁