Đang chuẩn bị liên kết để tải về tài liệu:
Addison Essential Csharp_6

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Hai lỗi biên dịch kết quả khẳng định một thực tế rằng các loại không tương thích, vì vậy họ sẽ không thành công chuyển đổi từ một đến khác. Các lỗi biên dịch thứ ba là do tái chỉ định của tài sản Tiêu đề. Các loại vô danh là không thay đổi | Anonymous Types and Implicitly Typed Local Variables 541 Listing 14.2 Type Safety and Immutability of Anonymous Types class Program static void Main var patentl new Title Bifocals YearOfPublication 1784 var patent2 new YearOfPublication 1877 Title Phonograph var patent3 new patent1.Title Year patent1.YearOfPublication ERROR Cannot implicitly convert type AnonymousType 1 to AnonymousType 2 patent1 patent2 ERROR Cannot implicitly convert type AnonymousType 3 to AnonymousType 2 patent1 patent3 ERROR Property or indexer AnonymousType 1.Title cannot be assigned to -- it is read only patent1.Title Swiss Cheese The resultant two compile errors assert the fact that the types are not compatible so they will not successfully convert from one to the other. The third compile error is caused by the reassignment of the Title property. Anonymous types are immutable so it is a compile error to change a property on an anonymous type once it has been instantiated. Although not shown in Listing 14.2 it is not possible to declare a method with an implicit data type parameter var . Therefore instances Chapter 14 Collection Interfaces with Standard Query Operators of anonymous types can only be passed outside the method in which they are created in only two ways. First if the method parameter is of type object the anonymous type instance may pass outside the method because the anonymous type will convert implicitly. A second way is to use method type inference whereby the anonymous type instance is passed as a method type parameter that the compiler can successfully infer. Calling void Method T T parameter using Function patentl therefore would succeed although the available operations on parameter within Function are limited to those supported by object. In spite of the fact that C allows anonymous types such as the ones shown in Listing 14.1 it is generally not recommended that you define them in this way. Anonymous types provide critical functionality with C 3.0 support for .

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.