Print a Simple ASCII Art in CSharp

Print a Simple ASCII Art in C#

Introduction

Programming isn’t only about numbers and text—it can also be fun and creative! One interesting way to practice is by printing ASCII art. ASCII art uses characters (like *, #, or letters) arranged in a certain way to form patterns or pictures. In this lesson, we will create a simple star pattern using Console.WriteLine in C#. This activity will help you practice output formatting and understand how text alignment works in the console. By completing this lesson, you’ll also see how programming can be used not just for problem-solving, but also for creativity.


Objectives

This lesson focuses on building both technical and creative skills. The objectives are aligned with OBE (Outcomes-Based Education):

  • Understand: Explain how text and symbols can be arranged in C# to form simple patterns.
  • Learn: Identify and use the correct Console.WriteLine syntax to output ASCII art.
  • Practice: Build and run a C# console app that displays a star pattern.
  • Apply: Modify the program to design your own ASCII art, like initials, shapes, or custom patterns.

Beginner-Friendly Source Code & Step-by-Step Instructions

Steps:

  1. Open VS Code. Make sure the .NET SDK is installed (dotnet --version in Terminal should show a version number).
  2. Create/open your course folder (e.g., D:\2025-1_doe_bsis_1a).
  3. Open the folder in VS Code (File → Open Folder…).
  4. Open a new Terminal (Terminal → New Terminal).
  5. Create a console project:
    dotnet new console -n ascii_art
    
  6. Navigate to the project:
    cd ascii_art
    
  7. Open Program.cs and replace its contents with the code below.
  8. Run the program:
    dotnet run
    

Program.cs

using System;

namespace AsciiArtApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Simple ASCII Art: Star Pattern\n");

            Console.WriteLine("   *   ");
            Console.WriteLine("  ***  ");
            Console.WriteLine(" ***** ");
            Console.WriteLine("*******");
            Console.WriteLine(" ***** ");
            Console.WriteLine("  ***  ");
            Console.WriteLine("   *   ");
        }
    }
}

Expected Output

Simple ASCII Art: Star Pattern

   *   
  ***  
 ***** 
*******
 ***** 
  ***  
   *   

Explanation of the Program

This program demonstrates how to print a star-shaped ASCII art using plain Console.WriteLine statements. We start by importing the System namespace so we can use the Console class. Inside the Main method, each Console.WriteLine prints one line of the pattern. By carefully arranging spaces and stars, the program creates a diamond/star-like figure.

Even though this code is repetitive, it is an important exercise for beginners to practice precision in formatting. Later on, we can improve this by using loops for more dynamic patterns, but for now, the goal is to get comfortable with console output.


Summary

In this lesson, you learned how to display a simple ASCII art pattern in C# using Console.WriteLine. This exercise teaches you how text formatting and alignment work in the console, while also encouraging creativity. While this method is limited for larger or dynamic art, it’s a fun way to apply what you’ve learned about basic program structure and output.


Quiz

  1. What does ASCII art use to form patterns?
    A. Numbers only
    B. Letters, numbers, and symbols
    C. Images
    D. Colors
  2. Which C# command is used to print a single line of ASCII art?
    A. Console.ReadLine()
    B. Console.Print()
    C. Console.WriteLine()
    D. Console.Out()
  3. What will happen if you remove spaces before the stars in the pattern?
    A. The program crashes
    B. The pattern becomes left-aligned
    C. Nothing changes
    D. The stars disappear
  4. Why is this approach not efficient for larger ASCII art?
    A. Too many repetitive lines
    B. It doesn’t display output
    C. C# doesn’t support ASCII art
    D. Console.WriteLine has a limit
  5. Which part of the C# program serves as the entry point to run ASCII art output?
    A. System namespace
    B. Main method
    C. Console class
    D. Using directive

Exercises, Assessment, and Lab Exam

Intro

To strengthen your understanding, here are exercises to help you improve formatting skills and get creative with ASCII art. These tasks will prepare you to use loops later for more advanced patterns.

Exercises

  1. Modify the program to print a bigger diamond with more rows.
  2. Create an ASCII triangle using only stars.
  3. Print the first letter of your name using stars.
  4. Replace stars with another symbol, like # or +.
  5. Design your own unique pattern and share it in class.

Assessment

  • Quiz: Answer the 5 multiple-choice questions.
  • Performance Task: Modify the code to create an ASCII heart or initials.

Lab Exam

  • Write a C# program that prints a rectangle made of stars without using loops.
  • Output should have 5 rows and 7 columns of stars.
  • Use only Console.WriteLine for each row.

You may visit our Facebook page for more information, inquiries, and comments. Please subscribe also to our YouTube Channel to receive free capstone projects resources and computer programming tutorials.

Hire our team to do the project.

, , , , , , , , , ,

Post navigation