IfStatement and CompareTo help

Hey CSharp,
you guys helped me with my programming last week so I figured I'd turn to you guys again. Normally I would attend to my professor's office hours as my first resource, but I am away from campus for the holiday weekend.
This time my problem is with alphabetizing three user-entered words using CompareTo. I had no problem with alphabetizing two user-entered words, but I am stumped and cannot find an answer online as to how to correctly write the code for three. I am sure its simple and I'll feel stupid afterwards.
My code so far:
Console.WriteLine("Please enter two words to be sorted by the console");
string userWord2 = Console.ReadLine();
string userWord3 = Console.ReadLine();
//string userWord4 = Console.ReadLine();

 if (userWord2.CompareTo(userWord3) < 0) { Console.WriteLine(userWord2); Console.WriteLine(userWord3); } else { Console.WriteLine(userWord3); Console.WriteLine(userWord2); } Console.ReadKey(); 

Also, I enjoyed the tips of how to clean up my code last week, but if a code is written using a specific variable and isn't inherently incorrect, it is written that way because that is how my professor requires it to be. Thanks in advance to anyone who helps me out.

by Welcome_To_Forever via /r/csharp

Leave a Reply