Review and Practice Exercises
Vaibhav • September 11, 2025
You’ve made it to the end of Chapter 1-congratulations! 🎉 Over the past several articles, you’ve learned the foundational concepts of programming and how to get started with C#. From understanding what programming is, to writing your first interactive console application, you’ve built a solid base. In this final article of the chapter, we’ll review what you’ve learned and walk through a few hands-on exercises to reinforce your understanding.
What You’ve Learned So Far
Let’s take a moment to reflect on the journey so far. You’ve covered:
- What programming is and why C# is a great language to learn
- How to set up your development environment using .NET and VS Code
- How to write, compile, and run your first C# program
- How the .NET runtime and CLR work behind the scenes
- How C# programs are structured using namespaces, classes, and the
Main
method - How to write comments and documentation to make your code readable
- How to use
Console.WriteLine
andConsole.ReadLine
for basic input and output - What algorithms are and how to think step-by-step
- A simple problem-solving methodology: understand, plan, implement, test
- How binary works and how numbers are stored in memory
- A gentle introduction to object-oriented programming
- Best practices for writing clean, readable, and maintainable code
That’s a lot of progress for one chapter! Now it’s time to put it all into practice.
Exercise 1: Print Your Name
Let’s start with something simple. Write a program that prints your name to the console.
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("My name is Vaibhav.");
}
}
This program uses Console.WriteLine
to display a message. You can replace the name with your own.
Try changing the message. What happens if you remove the semicolon? What if you use Console.Write
instead?
Exercise 2: Ask for the User’s Name
Now let’s make the program interactive. Ask the user for their name and greet them.
using System;
class Program
{
static void Main(string[] args)
{
Console.Write("What is your name? ");
string name = Console.ReadLine();
Console.WriteLine("Hello, " + name + "!");
}
}
This program uses Console.ReadLine
to get input from the user and stores it in a variable called
name
. Then it uses Console.WriteLine
to greet the user.
Try running the program and entering different names. What happens if you press Enter without typing anything?
Exercise 3: Ask for Name and Favorite Color
Let’s build on the previous example. Ask the user for their name and their favorite color, then print a message using both.
using System;
class Program
{
static void Main(string[] args)
{
Console.Write("What is your name? ");
string name = Console.ReadLine();
Console.Write("What is your favorite color? ");
string color = Console.ReadLine();
Console.WriteLine(name + ", your favorite color is " + color + ".");
}
}
This program introduces multiple inputs and shows how to combine them in a single message. You’re using string concatenation to build the output.
Try changing the order of the questions. What happens if you swap name
and color
in
the final message?
Exercise 4: Binary Character Viewer
Let’s revisit binary. Write a program that asks the user to enter a single character and prints its binary representation.
using System;
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a single character: ");
string input = Console.ReadLine();
if (input.Length > 0)
{
char character = input[0];
int ascii = (int)character;
string binary = Convert.ToString(ascii, 2);
Console.WriteLine("Character: " + character);
Console.WriteLine("ASCII value: " + ascii);
Console.WriteLine("Binary: " + binary);
}
}
}
This program uses type casting and the Convert.ToString
method to show the binary form of a
character. It’s a great way to connect what you learned about binary with actual code.
Try entering different characters like A
, z
, or 5
. What binary values do
you get?
Exercise 5: Comment Your Code
Take any of the programs above and add comments to explain what each line does. For example:
using System;
class Program
{
static void Main(string[] args)
{
// Ask for the user's name
Console.Write("What is your name? ");
// Read the input and store it in a variable
string name = Console.ReadLine();
// Greet the user
Console.WriteLine("Hello, " + name + "!");
}
}
Comments help you and others understand your code. They’re especially useful when you come back to a program after a few days or weeks.
Exercise 6: Write Your Own Algorithm
Choose a simple task-like asking for a user’s age or favorite food-and write out the steps in plain English before coding. For example:
1. Ask the user for their favorite food
2. Read the input
3. Display a message using the input
Then turn it into code:
Console.Write("What is your favorite food? ");
string food = Console.ReadLine();
Console.WriteLine("Yum! I like " + food + " too.");
Practicing this process-plan first, then code-will help you become a better problem solver.
Keep Practicing
The best way to learn programming is by doing. Don’t worry if your code isn’t perfect. Don’t worry if you make mistakes. That’s how you learn.
Try writing your own small programs. Here are a few ideas:
- Ask the user for their name and age, then print a message
- Ask for two favorite things and combine them in a sentence
- Print a short poem or quote using multiple
Console.WriteLine
statements
You don’t need to build anything big yet. Just keep experimenting, testing, and having fun.
Save your practice programs in a folder. Name each file clearly (like
GreetUser.cs
) so you can come back and review your progress later.
Summary
In this article, you reviewed everything you’ve learned in Chapter 1 and practiced writing simple programs using input, output, and basic logic. You now know how to:
- Write and run a C# program using
Main
- Use
Console.WriteLine
andConsole.ReadLine
for interaction - Plan your logic using algorithms and pseudocode
- Write clean, readable code with comments
- Apply what you’ve learned through hands-on exercises
You’ve built a strong foundation. In the next chapter, we’ll dive into debugging-how to find and fix errors in your code. But for now, take a moment to celebrate how far you’ve come. You’re officially a C# programmer in the making!