The C# Programming Language phần 6

Bảng sau đây cho thấy một danh sách lớp được gọi là, mà thực hiện một danh sách growable của các đối tượng. Lớp có chứa một số ví dụ của các loại phổ biến nhất của các thành viên chức lớp học và các đối tượng Các trường liên tục nhà xây dựng | Enums EditBox editBox IControl control new EditBox editBox Error no such method Ok Enums An enum type is a distinct value type with a set of named constants. The following example declares and uses an enum type named Color with three constant values Red Green and Blue. using System enum Color Red Green Blue class Test static void PrintColor Color color switch color case Red break case Green break case Blue break default Unknown color break static void Main Color c PrintColor c PrintColor Each enum type has a corresponding integral type called the underlying type of the enum type. An enum type that does not explicitly declare an underlying type has an underlying type of int. An enum type s storage format and range of possible values are determined by its underlying type. The set of values that an enum type can take on is not 1. Introduction 39 1. Introduction 1. Introduction limited by its enum members. In particular any value of the underlying type of an enum can be cast to the enum type and is a distinct valid value of that enum type. The following example declares an enum type named Alignment with an underlying type of sbyte. enum Alignment sbyte Left -1 Center 0 Right 1 As shown by the previous example an enum member declaration can include a constant expression that specifies the value of the member. The constant value for each enum member must be in the range of the underlying type of the enum. When an enum member declaration does not explicitly specify a value the member is given the value zero if it is the first member in the enum type or the value of the textually preceding enum member plus one. Enum values can be converted to integral values and vice versa using type casts. For example int i int int i 2 Color c Color 2 Color c The default value of any enum type is the .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
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.