C 2.0 practical guide for programmers PHẦN 4

Trong bảng liệt kê này, trong nước là 0, quốc tế là 2, Home là 3, và làm việc là 4. Trong ví dụ sau đây, tất cả các hằng số được quy định cụ thể: enum DeliveryAddress {trong nước = 1, quốc tế = 2, Trang chủ = 4, làm việc = 8}, loại tách rời cơ bản có thể được quy định cụ thể như tốt. | 62 Chapter 4 Unified Type System In this enumeration Domestic is 0 International is 2 Home is 3 and Work is 4. In the following example all constants are specified enum DeliveryAddress Domestic 1 International 2 Home 4 Work 8 The underlying integral type can be specified as well. Instead of the default int the byte type can be used explicitly for the sake of space efficiency enum DeliveryAddress byte Domestic 1 International 2 Home 4 Work 8 Unlike its predecessors in C and Java enumerations in C inherit from the class providing the ability to access names and values as well as to find and convert existing ones. A few of these methods are as follows Accessing the name or value of an enumeration constant string GetName Type enumType object value string GetNames Type enumType Array GetValues Type enumType Determining if a value exists in an enumeration bool IsDefined Type enumType object value Converting a value into an enumeration type overloaded for every integer type object ToObject Type enumType object value object ToObject Type enumType intType value Historically enumerations have been used as a convenient procedural construct to improve software readability. They simply mapped names to integral values. Consequently enumerations in C C were not extensible and hence not object oriented. Enumerations in C however are extensible and provide the ability to add new constants without modifying existing enumerations thereby avoiding massive recompilations of code. At the highest level value types are subdivided into three categories StructType EnumType and NullableType the former including the simple types such as char and int. The complete EBNF of all value types in C is summarized below where TypeName is a I EBNF I user-defined type identifier for structures and enumerations ValueType StructType EnumType NullableType . StructType TypeName SimpleType . SimpleType NumericType bool . NumericType IntegralType RealType decimal char . IntegralType sbyte short .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.