You can customize Visual Studio .NET to create the Run() method for you each time you create a console application. Before doing this, make sure you have a current backup of your entire installation. Then follow these steps to create a template for console applications for use with this book:

  1. Navigate to the Templates directory. Typically this path is Program Files\ Microsoft Visual Studio .NET\ VC#\ VC#Wizards\ CSharpConsoleWiz\ Templates\ 1033.

  2. Make a copy of file1.cs.

  3. Open file1.cs to edit using Notepad or similar text editor.

  4. Remove whatever comments you no longer want in your console applications.

  5. Change the class name from [! output SAFE_CLASS NAME] to Tester.

  6. Remove the parameters to Main() and the attribute above it.

  7. Add the Run() method.

  8. Instantiate Tester and invoke Run from within Main().

  1. Save the file and start up Visual Studio .NET. Create a new console application to test that your code worked.

If at any time you decide you'd like to revert to the original template, simply restore the backup copy of file1.cs that you made earlier.

8.7.3 Using Static Fields

A common use of static member variables, or fields, is to keep track of the number of instances/objects that currently exist for your class. In the next example, you create a Cat class. The Cat class might be used in a pet-store simulation.





0 comments

Post a Comment