TAILIEUCHUNG - Beginning Microsoft Visual C# 2008 PHẦN 2

Các loại chuyển đổi rõ ràng bạn đã được sử dụng trong rất nhiều các thử ví dụ trong cuốn sách này là một chút khác nhau từ những người bạn đã nhìn thấy cho đến nay trong chương này. Bạn đã được chuyển đổi các giá trị chuỗi thành số bằng cách sử dụng các lệnh như (), | Chapter 5 More About Variables Figure 5-2 The property you want to change is one of the Advanced settings so you click the Advanced button. In the dialog that appears enable the Check for arithmetic overflow underflow option as shown in Figure 5-3. By default this setting is disabled but enabling it provides the checked behavior detailed previously. Figure 5-3 99 Part I The C Language Explicit Conversions Using the Convert Commands The type of explicit conversion you have been using in many of the Try It Out examples in this book is a bit different from those you have seen so far in this chapter. You have been converting string values into numbers using commands such as which is obviously something that won t work for every possible string. If for example you try to convert a string like Number into a double value using then you will see the dialog shown in Figure 5-4 when you execute the code. Figure 5-4 As you can see the operation fails. For this type of conversion to work the string supplied must be a valid representation of a number and that number must be one that won t cause an overflow. A valid representation of a number is one that contains an optional sign that is plus or minus zero or more digits an optional period followed by one or more digits and an optional e or E followed by an optional sign and one or more digits and nothing else except spaces before or after this sequence . Using all of these optional extras you can recognize strings as complex as as being a number. There are many such explicit conversions that you can specify in this way as the following table shows Command Result val val converted to bool val val converted to byte val val converted to char val val converted to decimal val val converted to double val val converted to short val val converted to int val val

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.