【正文】
ode that return information whereas a method generally does not return information. For our purposes however, we generalize and refer to them both as functions. Functions can have four kinds of parameters: ? Input parameters have values that are sent into the function, but the function cannot change those values. ? Output parameters have no value when they are sent into the function, but the function can give them a value and send the value back to the caller. ? Reference parameters pass in a reference to another value. They have a value ing in to the function, and that value can be changed inside the function. ? Params parameters define a variable number of arguments in a list. C and the CLR work together to provide automatic memory management. You don39。t lose any information (for example, you can convert an int to a long without losing any data because a long is larger than an int). Explicit conversions may cause you to lose data (for example, converting a long into an int may result in a loss of data because a long can hold larger values than an int). You must write a cast operator into your code to make an explicit conversion happen. CrossReference Refer to Chapter 3, Working with Variables, for more information about implicit and explicit conversions. You can work with both onedimensional and multidimensional arrays in C. Multidimensional arrays can be rectangular, in which each of the arrays has the same dimensions, or jagged, in which each of the arrays has different dimensions. Classes and structures can have data members called properties and fields. Fields are variables that are associated with the enclosing class or structure. You may define a structure called Employee, for example, that has a field called Name. If you define a variable of type Employee called CurrentEmployee, you can retrieve the employee39。 public string FullName() { } return FirstName + LastName。s not in a class. Classes can have constructors, which execute when an object of the class is created, and a destructor, which executes when an object of the class is destroyed. Classes support single inheritance, and all classes ultimately derive from a base class called object. C supports versioning techniques to help your classes evolve over time while maintaining patibility with code that uses earlier versions of your classes. As an example, take a look at a class called Family. This class contains the two static fields that hold the first and last name of a family member as well as a method that returns the full name of the family member. class Class1 { public string FirstName。t define a variable outside of a class, and you can39。t sound familiar to you, don39。t pay much attention to this programming paradigm. After the notion of objectoriented development began to gain acceptance, it became clear that C needed to be refined to embrace this new way of thinking about code. C++ was created to embody this refinement. It was designed to be backwardly patible with C (such that all C programs would also be C++ programs and could be piled with a C++ piler). The major addition to the C++ language was support for this new object concept. The C++ language added support for classes (which are templates of objects), and enabled an entire generation of C programmers to think in terms of objects and their behavior. The C++ language is an improvement over C, but it still has some disadvantages. C and C++ can be hard to get a handle on. Unlike easytouse languages like Visual Basic, C and C++ are very low level and require you to do a lot of coding to make your application run well. You have to write your own code to handle issues such as memory management and error checking. C and C++ can result in very powerful applications, but you need to ensure that your code works well. One bug can make the entire application crash or behave unexpectedly. Because of the C++ design goal of retaining backward patibility with C, C++ was unable to break away from the low level nature of C. Microsoft designed C to retain much of the syntax of C and C++. Developers who are familiar with those languages can pick up C code and begin coding relatively quickly. The big advantage to C, however, is that its designers chose not to make it backwardly patible with C and C++. While this may seem like a bad deal, it39。t care. Objects weren39。ll learn more about objects in Chapter 8, Writing ObjectOriented Code. For now, think of an object as a collection of data and a set of operations that can be performed on that data. Objectstyle coding could be acplished using C, but the notion of an object was not enforced by the language. If you wanted to structure your code to resemble an object, fine. If you didn39。C A History of C, C++, and C The C programming language was created in the spirit of the C and C++ programming languages. This accounts for its powerful features and easy learning curve. The same can39。t be said for C and C++, but because C was created from the ground up, Microsoft took the liberty of removing some of the more burdensome features — such as pointers. This section takes a look at the C and C++ languages, tracing their evolution into C. The C programming language was originally designed for use on the UNIX operating system. C was used to create many UNIX applications, including a C piler, and was eventually used to write UNIX itself. Its widespread acceptance in the academic arena expanded to include the mercial world, and software vendors such as Microsoft and Borland released C pilers for personal puters. The original Windows API was designed to work with Windows code written in C, and the latest set of the core Windows ope