ms_learn_csharp/010_conventions/conventions/Program.cs

24 lines
506 B
C#
Raw Permalink Normal View History

2024-07-17 16:32:54 -04:00
/*
This code reverses a message, counts the number of times
a particular character appears, then prints the results
to the console window.
*/
string orig_msg = "The quick brown fox jumps over the lazy dog.";
char[] msg = orig_msg.ToCharArray();
Array.Reverse(msg);
int ltr_count = 0;
foreach (char ltr in msg) {
if (ltr == 'o') {
ltr_count++;
}
}
string new_message = new String(msg);
Console.WriteLine(new_message);
Console.WriteLine($"'o' appears {ltr_count} times.");