ms_learn_csharp/010_conventions/conventions/Program.cs

24 lines
506 B
C#

/*
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.");