C Primer Plus (5th Edition)
This book is divided into 23 chapters and 6 appendixes. Five appendixes (Appendix B F) are located on SAMS Web site at www.samspublishing.com.
Chapter 1: "Computers and Computer Programming: Basic Concepts" starts with an overview of the fundamental computer hardware and software concepts required to begin learning C# and computer programming. The last part of the chapter introduces .NET and highlights important services provided by this essential C# programming platform.
Chapter 2: "Your First C# Program" introduces you to the basic software development phases that successful programmers go through to produce robust computer programs and gives you an initial feel for object-oriented programming. The chapter culminates by showing you the mechanics of writing, compiling, and running a simple C# program.
Chapters 3 and 4: Often, an enjoyable and efficient way to learn about an unknown location you visit for the first time is to join a guided tour. Chapter 3, "A Guided Tour Through C#: Part I," and Chapter 4, "A Guided Tour Through C#: Part II," take you to the main attractions of the C# language needed to write simple C# programs. Rather than getting bogged down by details and theory, the aim in these two chapters is to kick start your ability to write simple C# programs and allow you to play and experiment with the language. This is achieved by letting the contents of a few simple C# programs dictate the hands-on and fast-paced story line of these two chapters.
Chapter 5: The first part of Chapter 5, "Your First Object-Oriented Program," builds on the practical knowledge you acquired from Chapters 3 and 4 to give you a deeper insight into the basic structure of the C# language. The second part elaborates on the object-oriented programming knowledge you have gained up until now and turns it into an object-oriented elevator simulation program.
Chapter 6: By now, you will know how to write simple object-oriented C# programs. However, many aspects of the C# language have intentionally been ignored to keep the fast track of the previous chapters free from obscuring and distracting elements. Chapter 6, "Types Part I: The Simple Types," and the remaining chapters of the book are devoted to letting you expand the basic kinds of C# programs you have mastered in the first five chapters. This is done through a systematic and thorough discussion of the many exciting and powerful elements in C# that you now have enough knowledge to appreciate, absorb, and use in the programs with which you might already be experimenting and playing.
Chapter 6 discusses the type concept in general and the simple types, used in most C# programs, in particular. It also introduces an important notation form that is used throughout the rest of the book to describe the syntax of the various C# elements.
Chapter 7: Types allow you to specify attributes about the data kept in a program. Operators in general act on these data. Without operators, program data remain motionless and in most cases useless. Chapter 7, "Types Part II: Operators, Enumerators, and Strings," provides an overview of the different kinds of operators found in C# and looks closer at the main arithmetic operators. Furthermore, the chapter discusses the derived types string (used to represent text) and enum (used to handle unchanging values). Several useful and interesting string-related program examples are presented and discussed.
Chapter 8: Branching statements allow programs to behave intelligently by reacting differently to different circumstances. Chapter 8, "Flow of Control Part I: Branching Statements and Related Concepts," contains elaborate discussions of the entire set of C# branching statement constructs if, if-else, and switch along with their close associates comparison and logical operators that also are pivotal for implementing the iteration statements presented in Chapter 9.
Chapter 9: Iteration statements are used to perform the same actions over and over again until some condition is no longer true. C#'s iteration statements, consisting of the while loop, the do-while loop, and the for loop, are discussed in Chapter 9, "Flow of Control Part II: Iteration Statements." Their treatment is elaborated by introducing the useful idea of nested iteration statements. Finally, the structured programming concept that contains proven principles about how to construct robust software on the very detailed design level is presented.
Chapter 10: An array is used to represent a small or large group of similar data items. Chapter 10, "Arrays Part I: Array Essentials," presents arrays and shows how they can be accessed efficiently by using the iteration statements presented in Chapter 9. It also introduces the foreach iteration statement specifically targeted at arrays and other collections of data items. The array is a reference type an important object-oriented concept. For that reason, arrays are used as examples in this chapter for teaching about reference types.
Chapter 11: Chapter 10 only deals with one-dimensional arrays designed for storing data elements that can be viewed as sitting on a line one after the other. Sometimes, data are better represented in two-dimensional tables. Our ability to represent these types of data with two-dimensional arrays is discussed in Chapter 11, "Arrays Part II: Multidimensional Arrays," together with arrays of three or more dimensions. The symbiotic relationship between multidimensional arrays and nested loops is a great example of how data structures and program logic go hand in hand. The chapter concludes by describing a couple famous algorithms for sorting and searching arrays and shows examples of how you can save countless programming hours by reusing the pre-built program parts found in .NET.
Chapter 12: Classes and objects are at the core of object-oriented programming. Classes are written by the programmer in the source code and act as blueprints for objects generated while the program is running. Objects collaborate to provide the functionality of a C# program. The first part of Chapter 12, "Class Anatomy Part I: static Class Members and Method Adventures," provides an overview of the ingredients that make up a class. The chapter then continues, as do Chapters 13 and 14, with a detailed look at each of those ingredients. Initially, the chapter looks at static class members that belong to a class rather than any particular object. This is followed by a closer look at method overloading a mechanism used to write different versions of methods all of same name but with different interfaces and implementations.
Chapter 13: "Class Anatomy Part II: Object Creation and Garbage Collection" looks at how new objects are initialized and old useless objects are disposed of. The latter is achieved through a built-in mechanism called garbage collection that automatically frees the memory (needed by the newly-created objects of the program) otherwise occupied by the useless objects.
Chapter 14: Properties, indexers and user-defined operator overloading are among the C# elements presented in Chapter 14, "Class Anatomy Part III: Writing Intuitive Code." They can, if used correctly, make the source code appear simpler and more intuitive.
Chapter 15: Namespaces assist you in organizing your classes while you write the source code as well as in keeping the classes easily accessible for other programmers when they reuse your classes. Chapter 15, "Namespaces, Compilation Units, and Assemblies," discusses namespaces, compilation units, and assemblies. It also demonstrates the flexibility by which they can be combined and shows you how their overall layout can be tailor-made to suit many different application configurations.
Chapter 16: Inheritance allows you to derive class A from class B and thereby let class A automatically inherit the features of class B. Features specific to class A can then be added manually in the code. Inheritance is a core concept in object-oriented programming with many virtues and is discussed at length in Chapter 16, "Inheritance Part I: Basic Concepts."
Chapter 17: "Inheritance Part II: abstract Functions, Polymorphism, and Interfaces," discusses polymorphism and how it allows you to program on a high abstraction level by letting you program against a few simple interfaces while the program takes care of the underlying complexities. Polymorphism is made possible by inheritance and abstract functions. Interfaces are also discussed in this chapter; they allow you to implement polymorphism across the rigid structures of one or more inheritance hierarchies.
Chapter 18: "Structs" looks at structs, which are lightweight alternatives to their close cousins classes.
Chapter 19: An exception is an abnormal condition in your program and causes a special exception object to be generated by .NET during the execution of the troubled program. Chapter 19, "Exception Handling," introduces exception handling and shows you how to avoid abrupt user-unfriendly program terminations, among other things.
Chapter 20: Conventionally, you must decide which actions a program will execute while you are writing the source code. Delegates allow you to postpone those decisions until the program is running. This allows your programs to be more dynamic with the ability to adjust to a variety of situations. Chapter 20, "Delegates and Events," discuss delegates and their relationship to events. Delegates form the basis for events that, through event-driven programming, have become an important part of many modern application types, especially graphical user interfaces (GUIs).
Chapter 21: "Preprocessing, XML Documentation and Attributes" explains how to conveniently exclude parts of your source code from being included in the finished program through the use of preprocessor directives. This is useful when you want to generate different application versions from the same source code. The chapter continues by looking at C#'s ability to extract XML-formatted source code documentation automatically and directly from the comments you insert into your source code. The chapter ends by presenting attributes and their ability to let you add additional declarative information to C#'s code elements.
Chapter 22: Files let you store data permanently on a disk. They allow programs to read them repeatedly and can be sent over networks to remote computers. Chapter 22, "File I/O Basics," contains a brief introduction to file I/O, which is short for file input (file flowing into a program) and file output (file flowing out of a program).
Chapter 23: When a method asks itself to be executed it is called a recursive method. The use of recursive methods is called recursion and this is covered in Chapter 23, "Recursion Fundamentals." Superficially, recursion seems to represent circular, impossible, and useless logic. However, as this chapter demonstrates through meticulous explanations, the recursion concept can be used to solve important computational problems.
Appendix A: "Answers to Review Questions and Exercises" contains the answers to the review questions and the programming exercises posed at the end of each chapter.
Appendix B: "Operator Precedence"
Appendix C: "Reserved Words In C#"
Appendix D: "Number Systems" discusses the binary, octal and hexadecimal number systems.
Appendix E: "Unicode Character Set"
Appendix F: "Using DOS Commands In The Console Window"