Store and Print Your Personal Details in CSharp

Store and Print Your Personal Details in C#


Introduction

In programming, one of the first skills you will learn is how to store and display information. This lesson will show you how to keep your personal details such as your name, age, and hobby in variables, and then print them to the console. Learning to store and print values is a foundation for more complex applications, such as forms, registration systems, and user profiles.


Objectives

Before we begin, it is important to know what we are aiming to achieve. Our objectives focus on the four pillars of Outcomes-Based Education (OBE):

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

  1. Understand – Explain how variables can be used to store personal information in C#.
  2. Learn – Identify the correct syntax for declaring and assigning values to variables.
  3. Practice – Write and run a program in VS Code that stores and prints your name, age, and hobby.
  4. Apply – Modify the program to store and print different types of personal information, such as your favorite food, color, or subject.

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

Step 1: Open VS Code and Terminal

  • Make sure the .NET SDK is installed (dotnet --version should show a version number).
  • Create/open your class folder (e.g., D:\2025-1_doe_bsis_1a).
  • Open the folder in VS Code.

Step 2: Create a new console project

dotnet new console -n personal_details
cd personal_details

Step 3: Replace Program.cs with this code

using System;

namespace PersonalDetailsApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Storing personal details in variables
            string name = "John Doe";
            int age = 20;
            string hobby = "Reading books";

            // Printing personal details
            Console.WriteLine("My Personal Details:");
            Console.WriteLine("Name: " + name);
            Console.WriteLine("Age: " + age);
            Console.WriteLine("Hobby: " + hobby);
        }
    }
}

Step 4: Run the program

dotnet run

Example Output

My Personal Details:
Name: John Doe
Age: 20
Hobby: Reading books

Summary

In this lesson, we learned how to declare variables, assign values, and print them to the console. By storing personal details such as name, age, and hobby, you practiced handling different data types like strings and integers. This is an important step because variables are the backbone of programming, enabling your applications to store and process user information effectively.


Multiple Choice Quiz

  1. Which keyword is used to store text in C#?
    A. int
    B. string
    C. float
    D. char
  2. What is the purpose of a variable?
    A. To repeat code
    B. To store and manage data
    C. To display errors
    D. To close the program
  3. If int age = 20;, what will Console.WriteLine(age); display?
    A. age
    B. 20
    C. int
    D. error
  4. Which operator is used to combine strings in C#?
    A. –
    B. +
    C. *
    D. /
  5. Why do we use variables in personal details programs?
    A. To save memory
    B. To allow dynamic storage and retrieval
    C. To avoid typing
    D. To run faster

Exercises, Assessment & Lab Exam

Intro

To strengthen your learning, here are exercises that help you modify and extend the program. These will prepare you to handle real-world applications where personal information must be processed.

Exercises

  1. Modify the program to also store and print your favorite subject.
  2. Change the program to display your details in one sentence (e.g., “My name is John Doe, I am 20 years old, and I love reading books.”).
  3. Ask the user to input their own details (use Console.ReadLine) and display them.
  4. Add another variable for your dream job and display it.
  5. Format the output neatly using line breaks and labels.

Assessment

  • Short Quiz: Complete the 5 multiple-choice questions above.
  • Performance Task: Modify the code so that it accepts user input for name, age, and hobby.

Lab Exam

  • Write a program in C# that stores and prints at least 5 personal details (e.g., name, age, hobby, favorite color, dream job).
  • Each detail must be stored in a variable and printed properly.

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