c编程语言概述毕业设计外文翻译内容摘要:
Note Single inheritance means that a C class can inherit from only one base class. C enables you to group your classes into a collection of classes called a namespace. Namespaces have names, and can help anize collections of classes into logical groupings. As you begin to learn C, it bees apparent that all namespaces relevant to the .NET Framework begin with System. Microsoft has also chosen to include some classes that aid in backwards patibility and API access. These classes are contained within the Microsoft namespace. Data types C lets you work with two types of data: value types and reference types. Value types hold actual values. Reference types hold references to values stored elsewhere in memory. Primitive types such as char, int and float, as well as enumerated values and structures, are value types. Reference types hold variables that deal with objects and arrays. C es with predefined reference types (object and string), as well as predefined value types (sbyte, short, int, long, byte, ushort, uint, ulong, float, double, bool, char, and decimal). You can also define your own value and reference types in your code. All value and reference types ultimately derive from a base type called object. C allows you to convert a value of one type into a value of another type. You can work with both implicit conversions and explicit conversions. Implicit conversions always succeed and 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 V about implicit and explic it 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。 s name by writing . Properties are like fields, but enable you to write code to specify what should happen when code accesses the value. If the employee39。 s name must be read from a database, for example, you can write code that says, when someone asks for the value of the Name property, read the name from the database and return the name as a string. Functions A function is a callable piece of code that may or may not return a value to the code that originally called it. An example of a function would be the FullName function shown earlier, in this chapter, in the Family class. A function is generally associated to pieces of code 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 need to write code that says allocate enough memory for an integer or free the memory that this object was using. The CLR monitors your memory usage and automatically retrieves more when you need it. It also frees memory automatically when it detects that it is no longer being used (this is also known as Garbage Collection). C provides a variety of operators that enable you to write mathematical and bitwise expressions. Many (but not all) of these operators can be redefined, enabling you to change how the operators work. C supports a long list of statements that enable you to define various execution paths within your code. Flow control statements that use keywords such as if, switch, while, for, break and continue enable your code to branch off into different paths, depending on the values of your variables. Classes can contain code and data. Each class member has something called an accessibility scope, which defines the member39。 s visibility to other objects. C supports public, protected, internal, protected internal, and private accessibility scopes. Variables Variables can be defined as constants. Constants have values that cannot change during the execution of your code. The value of pi, for instance, is a good example of a constant, because its value won39。 t be changing as your code runs. Enum type declarations specify a type name for a related group of constants. For example, you could define an enum of Plas with values of Mercury, V those names in your code. Using the enum names in code makes code more readable than if you used a number to represent each pla. C provides a builtin mechanism for defining and handling events. If you write a class that performs a lengthy operation, you may want to invoke an event when the operation is pleted. Clients can subscribe to that event and catch the event in their code, which enables them to be notified when you have pleted your lengthy operation. The event han。c编程语言概述毕业设计外文翻译
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。
用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。