TAILIEUCHUNG - Apress accelerared C# 2010_7

Tham khảo tài liệu 'apress accelerared c# 2010_7', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | CHAPTER 11 GENERICS Constructed Types Control Accessibility When you build constructed types from generic types you must consider the accessibility of both the generic type and the types provided as the type arguments in order to determine the accessibility of the whole constructed type. For example the following code is invalid and will not compile public class Outer private class Nested public class GenericNested T private GenericNested Nested field1 public GenericNested Nested field2 Ooops The problem is with field2. The Nested type is private so how can GenericNested Nested possibly be public Of course the answer is that it cannot. With constructed types the accessibility is an intersection of the accessibility of the generic type and the types provided in the argument list. Generics and Inheritance C generic types cannot directly derive from a type parameter. However you can use the following type parameters to construct the base types they do derive from This is invalid public class MyClass T T But this is valid. public class MyClass T Stack T Tip With C templates deriving directly from a type parameter provides a special flexibility. If you ve ever used the Active Template Library ATL to do COM development you have no doubt come across this technique because ATL employs it extensively to avoid the need for virtual method calls. The same technique is used with C templates to generate entire hierarchies at compile time. For more examples I suggest you read Andrei Alexandrescu s Modern C Design Generic Programming and Design Patterns Applied Boston MA Addison- 325 CHAPTER 11 GENERICS Wesley Professional 2001 . This is yet another example showing how C templates are static in nature whereas C generics are dynamic. Let s examine techniques that you can use to emulate the same behavior to some degree. As is often the case you can add one more level of indirection to achieve something similar. In C when a template type derives directly from one of the type .

TỪ KHÓA LIÊN QUAN
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.