Most computer applications that solve real-world problems are much larger than the applications presented in the first few chapters of this book. Experience has shown that the best way to develop and maintain a large application is to construct it from small, simple pieces. This technique is called divide and conquer. We introduced methods in Chapter 4. In this chapter, we study methods in more depth. We emphasize how to declare and use methods to facilitate the design, implementation, operation and maintenance of large applications.
You will see that it is possible for certain methods, called static methods, to be called without the need for an object of the class to exist. You will learn how to declare a method with more than one parameter. You will also learn how C# is able to keep track of which method is currently executing, how value-type and reference-type arguments are passed to methods, how local variables of methods are maintained in memory and how a method knows where to return after it completes execution.
We discuss simulation techniques with random-number generation and develop a version of the casino dice game called craps that uses most of the programming techniques you have learned to this point in the book. In addition, you will learn to declare values that cannot change (i.e., constants). You will also learn to write methods that call themselvesthis is called recursion.
Many of the classes you will use or create while developing applications will have more than one method of the same name. This technique, called method overloading, is used to implement methods that perform similar tasks but with different types or different numbers of arguments.
Packaging Code in C# |
Preface
Index
Introduction to Computers, the Internet and Visual C#
Introduction to the Visual C# 2005 Express Edition IDE
Introduction to C# Applications
Introduction to Classes and Objects
Control Statements: Part 1
Control Statements: Part 2
Methods: A Deeper Look
Arrays
Classes and Objects: A Deeper Look
Object-Oriented Programming: Inheritance
Polymorphism, Interfaces & Operator Overloading
Exception Handling
Graphical User Interface Concepts: Part 1
Graphical User Interface Concepts: Part 2
Multithreading
Strings, Characters and Regular Expressions
Graphics and Multimedia
Files and Streams
Extensible Markup Language (XML)
Database, SQL and ADO.NET
ASP.NET 2.0, Web Forms and Web Controls
Web Services
Networking: Streams-Based Sockets and Datagrams
Searching and Sorting
Data Structures
Generics
Collections
Appendix A. Operator Precedence Chart
Appendix B. Number Systems
Appendix C. Using the Visual Studio 2005 Debugger
Appendix D. ASCII Character Set
Appendix E. Unicode®
Appendix F. Introduction to XHTML: Part 1
Appendix G. Introduction to XHTML: Part 2
Appendix H. HTML/XHTML Special Characters
Appendix I. HTML/XHTML Colors
Appendix J. ATM Case Study Code
Appendix K. UML 2: Additional Diagram Types
Appendix L. Simple Types
Index