TAILIEUCHUNG - Returning Strongly Typed Column Values

Returning Strongly Typed Column Values Up to this point, you've retrieved column values from a DataReader only as generic objects of the class | Returning Strongly Typed Column Values Up to this point you ve retrieved column values from a DataReader only as generic objects of the class such objects are often referred to as being of the C object type . Note All classes in C are derived from the class. I ll rewrite the while loop shown in the example in the previous section to show how you store column values as objects of the class while object productID productsSqlDataReader productIDColPos object productName productsSqlDataReader productNameColPos object unitPrice productsSqlDataReader unitPriceColPos object unitsInStock productsSqlDataReader unitsInStockColPos object discontinued productsSqlDataReader discontinuedColPos productID productID productName productName unitPrice unitPrice unitsInStock unitsInStock discontinued discontinued This code results in the same output as Listing . All I did in Listing is to explicitly show that a DataReader returns a column value as an object of the class by default. When an object of the class is displayed by the method the object is first implicitly converted to a string and then displayed. That s fine for just displaying the column values but what if you want to perform some kind of calculation with a value To do that you must first cast the value to a specific type. The following example casts the unitPrice object to a decimal and then multiplies it by decimal newUnitPrice decimal unitPrice Note You add an m to the end of a literal number to indicate it is of the decimal type. Casting an object to a specific type works but it s not very elegant. It also goes against the one of the main benefits of a modern programming language use of strong typing. Strongly typing means that you pick the type of a variable or object when declaring it. The main .

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.