Print Your Name, Age and Hobby in CSharp

Print Your Name, Age, and Hobby in C#

Introduction

After creating your first “Hello, World!” program, it’s time to make your console application more personal. In this lesson, you’ll learn how to display multiple lines of text by printing your name, age, and hobby. This builds on your understanding of the C# program structure, while practicing the use of Console.WriteLine() for organized output.

Learning Objectives

By the end of this lesson, you will be able to:

  • Understand how to use Console.WriteLine() to display multiple pieces of information.
  • Learn the concept of structured output formatting in C#.
  • Practice writing a simple console program that prints personal details (name, age, hobby).
  • Apply the knowledge by creating customized output to simulate an introduction program.

Step-by-Step Instructions

Step 1: Create a New Console Project

  1. Open VS Code.
    2. Open your folder (example: D:\2025-1_doe_bsis_1a).
    3. Open the terminal (Ctrl + ~).
    4. Create a new project:

    dotnet new console -n personal_info

    This creates:
    – personal_info.csproj
    – Program.cs

Step 2: Replace Program.cs with This Code

using System;

namespace PersonalInfoApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("My Personal Information:");
            Console.WriteLine("Name: John Doe");
            Console.WriteLine("Age: 20");
            Console.WriteLine("Hobby: Playing Guitar");
        }
    }
}

Step 3: Run the Program

3.1 Navigate into your project folder:

cd personal_info

3.2Run the program:

dotnet run

Expected Output:

My Personal Information:
Name: John Doe
Age: 20
Hobby: Playing Guitar

Summary

This lesson introduced printing multiple outputs using Console.WriteLine(). You learned how to display your name, age, and hobby in an organized way. By practicing this, you build confidence in writing programs that present information clearly, which is the foundation for more interactive applications later.

Quiz

  1. Which command runs the program in VS Code?
    A. run dotnet
    B. dotnet run
    C. console.run
    D. execute program
  2. Why do we use multiple Console.WriteLine() statements?
    A. To combine input and output
    B. To display multiple lines of information
    C. To create a loop
    D. To declare variables
  3. Which line would you modify to change the hobby?
    A. Console.WriteLine(“Name: John Doe”);
    B. Console.WriteLine(“Hobby: Playing Guitar”);
    C. Console.WriteLine(“Age: 20”);
    D. namespace PersonalInfoApp
  4. If you remove using System;, what will happen?
    A. Nothing will change
    B. Program will not compile
    C. Output will double
    D. Program will run faster
  5. Which is the best way to display structured personal information?
    A. Write everything in one Console.WriteLine()
    B. Use multiple Console.WriteLine() for readability
    C. Remove namespace
    D. Avoid using comments

Exercises, Assessments, and Lab Exam

Learning programming means practicing through hands-on coding. Here are activities to help you improve:

  • Exercises:
  1. Change the details to your own name, age, and hobby.
  2. Add two more hobbies and print them.
  3. Format your output neatly with separators like ====.
  • Assessment: Create a program that prints your full name, age, hobby, and favorite quote.
  • Lab Exam: Write a program that displays five pieces of personal information (e.g., Name, Age, Course, Section, Hobby) in a structured format.

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