Đang chuẩn bị liên kết để tải về tài liệu:
Apress Introducing Dot Net 4 With Visual Studio_5

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

Tham khảo tài liệu 'apress introducing dot net 4 with visual studio_5', công nghệ thông tin, hệ điều hà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 .