Free mag vol1 | Page 127

CHAPTER 2  BUILDING C# APPLICATIONS Refactoring Technique Meaning in Life Remove Parameters Remove a given argument from the current list of parameters (as you would expect) Rename Allows you to rename a code token (method name, field, local variable, and so on) throughout a project To illustrate refactoring in action, update your Main() method with the following simple code: static void Main(string[] args) { // Set up Console UI (CUI) Console.Title = "My Rocking App"; Console.ForegroundColor = ConsoleColor.Yellow; Console.BackgroundColor = ConsoleColor.Blue; Console.WriteLine("*************************************"); Console.WriteLine("***** Welcome to My Rocking App *****"); Console.WriteLine("*************************************"); Console.BackgroundColor = ConsoleColor.Black; } // Wait for Enter key to be pressed. Console.ReadLine(); While there is nothing wrong with the preceding code as it now stands, imagine that you want to display this welcome message at various places throughout your program. Rather than retyping the same exact console user interface logic, it would be ideal to have a helper function that could be called to do so. Given this, you will apply the Extract Method refactoring to your existing code. First, select each code statement within Main() (except the final call to Console.ReadLine()) using the editor. Then right-click the selected text and select the Extract Method option within the Refactor context menu (see Figure 2-14). 60