C# Beginner's Guide: Create a Console Message Program for HNDIT Students

C# Beginner's Guide: Create a Console Message Program for HNDIT Students

C# program for beginners that prints a message to the console:

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");

        Console.WriteLine("Welcome to C# programming!");

        Console.ReadKey();
    }
}

Explanation:

  1. using System; – This includes the System namespace, which contains basic classes like Console that we need for input/output.

  2. class Program – Defines a class named Program.

  3. static void Main(string[] args) – The Main method is the entry point of a C# console application.

  4. Console.WriteLine("Hello, World!"); – Prints "Hello, World!" and moves to the next line.

  5. Console.ReadKey(); – Waits for the user to press a key before closing the console window.

1. Print Hello World

Write a simple program that prints "Hello, World!" to the console.

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");
    }
}

2. Print a Simple Math Result

Write a program that directly prints the result of adding two numbers.

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(10 + 20); // Prints the sum of 10 and 20
    }
}

3. Print a Multiplication Result

Print the result of multiplying two numbers directly.

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(5 * 3); // Prints the result of 5 multiplied by 3
    }
}

4. Print a Simple Message Multiple Times

Print a message multiple times using Console.WriteLine.

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("I am learning C#!");
        Console.WriteLine("I am learning C#!");
        Console.WriteLine("I am learning C#!");
    }
}

5. Print a Simple Shape

Print a square shape using asterisks (*).

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("*****");
        Console.WriteLine("*****");
        Console.WriteLine("*****");
        Console.WriteLine("*****");
        Console.WriteLine("*****");
    }
}

6. Print the Result of the Division

Write a program that prints the result of dividing two numbers directly.

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(100 / 5); // Prints the result of 100 divided by 5
    }
}

7. Print Your Name and Age

Write a program that prints your name and age to the console.

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("My name is [Your Name].");
        Console.WriteLine("I am [Your Age] years old.");
        Console.ReadKey();
    }
}

Task: Replace [Your Name] and [Your Age] with your actual name and age.


8.Print a List of Fruits

Print a list of fruits in separate lines.

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("List of fruits:");
        Console.WriteLine("1. Apple");
        Console.WriteLine("2. Banana");
        Console.WriteLine("3. Mango");
        Console.WriteLine("4. Orange");
        Console.WriteLine("5. Pineapple");
    }
}

9. Print Simple Shapes Using Asterisks

Print a triangle shape using asterisks (*).

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("  *  ");
        Console.WriteLine(" *** ");
        Console.WriteLine("*****");
    }
}

10. Print Multiple Lines of Text

Print a few sentences in separate lines.

csharpCopy codeusing System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("C# is a powerful programming language.");
        Console.WriteLine("It is widely used for developing desktop and web applications.");
        Console.WriteLine("Let's keep practicing and improving!");
    }
}

break;