This simple C# program demonstrates how to convert lowercase letters to uppercase using the ToUpper()
method.
The code iterates through the lowercase alphabet and converts each letter to uppercase using the ToUpper()
method. It then prints the uppercase letters to the console.
using System;
public class Program
{
// C# Main method - The program start here
static void Main(string[] args)
{
string alphabet = "abcdefghijklmnopqrstuvwxyz";
// Iteration in each letter in the alphabet string
foreach (char letter in alphabet){
// definition of new variable 'letterCapitalCase' for converting char type into string output
string letterCapitalCase = letter.ToString().ToUpper();
// Output method
Console.WriteLine(letterCapitalCase);
}
}
}
- Install .NET SDK: If you don't have it already, download and install the .NET SDK from https://dotnet.microsoft.com/download.
- Compile the code: Open a command prompt and navigate to the directory containing the C# file (
Program.cs
). Run the following command to compile the code:dotnet build
- Run the program: Execute the following command to run the compiled program:
dotnet run
- Install .NET SDK: Install the .NET SDK using your distribution's package manager. For example, on Ubuntu:
sudo apt update sudo apt install dotnet-sdk-6.0
- Compile the code: Open a terminal and navigate to the directory containing the C# file (
Program.cs
). Run the following command to compile the code:dotnet build
- Run the program: Execute the following command to run the compiled program:
dotnet run
The program will output the uppercase alphabet to the console, one letter per line:
A
B
C
...
Z
This repository serves as a basic example of string manipulation in C# and demonstrates the use of the ToUpper()
method
and the need of Type conversion from char type from string type, using ToString() method
.