Exercise
Convert Any File To Uppercase
Objective
Write a program to read a file (of any kind) and dump its content to another file, changing the lowercase letters to uppercase.
You must deliver only the ".cs" file, with you name in a comment.
Write Your C# Exercise
C# Exercise Example
// Importing the System namespace for basic functionalities like Console I/O
using System;
// Importing the System.IO namespace to handle file operations like reading and writing files
using System.IO;
class ConvertToUppercaseFile // Define the class ConvertToUppercaseFile
{
// Method to read a file, convert its content to uppercase, and save it to a new file
public static void ConvertFileToUppercase(string inputFileName, string outputFileName)
{
string fileContent = File.ReadAllText(inputFileName); // Reading the content of the input file
string uppercasedContent = fileContent.ToUpper(); // Converting the file content to uppercase
File.WriteAllText(outputFileName, uppercasedContent); // Writing the uppercase content to the output file
Console.WriteLine($"File content has been converted to uppercase and saved to {outputFileName}"); // Printing a confirmation message
}
// Main method - entry point of the program
static void Main(string[] args)
{
Console.Write("Enter the input file name (with extension): "); // Asking the user for the input file name
string inputFileName = Console.ReadLine(); // Reading the input file name entered by the user
string outputFileName = Path.GetFileNameWithoutExtension(inputFileName) + "_uppercase" + Path.GetExtension(inputFileName); // Creating the output file name with "_uppercase" suffix
ConvertToUppercaseFile.ConvertFileToUppercase(inputFileName, outputFileName); // Calling the method to convert the file content to uppercase
}
}