Program to Display Characters from A to Z Using Loop - (C# Basic Programs)
Displaying characters from A to Z using a loop is a common programming exercise that helps beginners to understand the C# language structure and syntax. In this tutorial, we will discuss a program to display characters from A to Z using a loop in C#.
Syntax
The syntax for displaying characters from A to Z using a loop in C# is:
for (char c = 'A'; c <= 'Z'; c++)
{
Console.Write(c + " ");
}
Example
using System;
class Program
{
static void Main(string[] args)
{
for (char c = 'A'; c <= 'Z'; c++)
{
Console.Write(c + " ");
}
Console.ReadLine();
}
}
Output
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Explanation
The program uses a for
loop to iterate through the ASCII values of characters from A to Z. It then prints each character to the console. The Console.ReadLine()
statement is included to keep the console window open after the program has finished executing.
Use
This program is a basic program in C# and is a good starting point for beginners who want to learn how to use loops and print characters to the console.
Summary
In this tutorial, we discussed a program to display characters from A to Z using a loop in C#. We covered the syntax, example, output, explanation, and use of this basic program. By practicing programs like this, beginners can improve their understanding of C# language and become comfortable with the syntax and structure.