Store and Display Product Details in C#
Table of Contents
- Store and Display Product Details in C#
- Introduction
- Objectives
- Beginner-Friendly Source Code & Step-by-Step Instructions
- Step 1: Open VS Code and Terminal
- Step 2: Create a new console project
- Step 3: Replace Program.cs with the code below
- Step 4: Run the program
- Example Output
- Summary
- Multiple Choice Quiz
- Exercises, Assessment & Lab Exam
- Intro
- Exercises
- Assessment
- Lab Exam
Introduction
In business and real-world applications, we often need to manage and display product details like name, price, and stock. This is a great way to understand how C# can be used to represent data in a program. In this lesson, we will create a simple C# console application that stores product information in variables and displays it neatly. By doing this, you will learn how to use different data types, combine text with numbers, and create structured outputs.
Objectives
This lesson focuses on Outcome-Based Education (OBE). By the end of this lesson, you should be able to:
Intro to Objectives: The goal of this activity is not just to write code but also to build essential programming habits—understanding concepts, learning the syntax, practicing through examples, and applying these skills to solve real-life problems.
- Understand – Explain how variables and data types are used to represent product information in C#.
- Learn – Identify and apply the correct syntax for declaring variables and printing details to the console.
- Practice – Write and run a C# console program that stores and displays product details.
- Apply – Modify the program to add new products or display formatted outputs for real-world style scenarios.
Beginner-Friendly Source Code & Step-by-Step Instructions
Step 1: Open VS Code and Terminal
- Make sure the .NET SDK is installed (
dotnet --version
). - Create/open your class folder (e.g.,
D:\2025-1_doe_bsis_1a
).
Step 2: Create a new console project
dotnet new console -n product_details
cd product_details
Step 3: Replace Program.cs with the code below
using System;
namespace ProductDetailsApp
{
class Program
{
static void Main(string[] args)
{
// Store product details
string productName = "Laptop";
double productPrice = 45999.99;
int productStock = 15;
// Display product details
Console.WriteLine("Product Details:");
Console.WriteLine("Name: " + productName);
Console.WriteLine("Price: ₱" + productPrice);
Console.WriteLine("Stock: " + productStock);
}
}
}
Step 4: Run the program
dotnet run
Example Output
Product Details:
Name: Laptop
Price: ₱45999.99
Stock: 15
Summary
In this lesson, you learned how to declare variables of different data types to store product details and print them to the console. This simple program demonstrates how programming concepts can be applied to real-world problems such as inventory management. By understanding this, you are preparing yourself for more complex applications like product catalogs, sales systems, and inventory management software.
Multiple Choice Quiz
- Which data type is most suitable for storing a product’s price?
A. int
B. double
C. string
D. bool - If a product’s name is “Shoes”, which variable declaration is correct?
A. string productName = Shoes;
B. string productName = “Shoes”;
C. int productName = “Shoes”;
D. char productName = Shoes; - What does
Console.WriteLine
do in this program?
A. Reads user input
B. Displays product details
C. Declares variables
D. Stores data in memory - Which symbol is used for string concatenation in C#?
A. &
B. +
C. *
D. % - Why do we need different data types (string, double, int) in this program?
A. To make the code shorter
B. To represent different kinds of values
C. To avoid using Console.WriteLine
D. To save memory only
Exercises, Assessment & Lab Exam
Intro
To deepen your understanding of variables and outputs, the following exercises will help you modify and extend the product details program. These activities will prepare you for handling more complex datasets in future lessons.
Exercises
- Change the values of productName, productPrice, and productStock to represent a new product.
- Add a second product with its own variables and display its details.
- Format the price to show only two decimal places (₱45999.99 → ₱45999.99).
- Display a message like: “We currently have X units of Y priced at Z.”
- Ask the user to enter product details (name, price, stock) and display them.
Assessment
- Quiz: Answer the 5 multiple-choice questions above.
- Performance Task: Create a program that stores details for two products and displays them side by side.
Lab Exam
- Write a program in C# that asks the user for:
- Product name
- Product price
- Product stock
- Then display the product details 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.