Coding Exercise - Write and Run C# program
Many beginners find it easy to understand C# concepts, but they often struggle to apply their logic in real programs.
This is completely normal!
The best way to overcome this challenge is through regular practice.
First, take your time to understand the program given below. Then, try running the C# code on your system. The more you practice, the better you will get.
So, don’t hesitate—start coding now and build your confidence step by step!
1️⃣ Print a String
Question:
Write a C# program to print "Welcome to C# Programming!"
.
Solution
using System;
class Program
{
static void Main()
{
Console.WriteLine("Welcome to C# Programming!");
}
}
Output
Welcome to C# Programming!
2️⃣ Print a Boolean Value
Question:
Write a C# program to print the Boolean value true
.
Solution:
using System;
class Program
{
static void Main()
{
Console.WriteLine(true);
}
}
Output:
True
3️⃣ Print a Floating-Point Number
Question:
Write a C# program to print the floating-point number 3.14159
Solution:
using System;
class Program
{
static void Main()
{
Console.WriteLine(3.14159);
}
}
Output:
3.14159
4️⃣ Print a Date and Time
Question:
Write a C# program to print the date January 31, 2025.
Solution:
using System;
class Program
{
static void Main()
{
Console.WriteLine(new DateTime(2025, 1, 31));
}
}
Output:
1/31/2025 12:00:00 AM
5️⃣ Print an Arithmetic Operation Result
Question:
Write a C# program to print the result of 100 / 4
.
Solution:
using System;
class Program
{
static void Main()
{
Console.WriteLine(100 / 4);
}
}
Output:
25
Final Thoughts!
Learning C# starts with small steps. First, understand the basics. Then, practice writing and running simple programs. Each program you try makes you better. Mistakes are normal, so don’t give up. Keep practicing, explore more, and enjoy coding. The more you code, the more confident you become. So, start now and have fun with C#!