Beginning Microsoft Visual C# 2008 PHẦN 4

Tạo một lớp được gọi là ShortCollection thực hiện IList và bao gồm một bộ sưu tập của các mục có kích thước tối đa. Điều này kích thước tối đa là một số nguyên có thể được cung cấp cho các nhà xây dựng của ShortCollection hoặc mặc định đến 10. | Chapter 12 Generics 4. What is wrong with the following code Fix it. public class StringGetter T public string GetString T T item return 5. Create a generic class called ShortCollection T that implements lList T and consists of a collection of items with a maximum size. This maximum size should be an integer that can be supplied to the constructor of ShortCollection T or defaults to 10. The constructor should also be able to take an initial list of items via a List T parameter. The class should function exactly like Collection T but throw an exception of type IndexOutOfRangeException if an attempt is made to add too many items to the collection or if the List T passed to the constructor contains too many items. 369 13 Additional OOP Techniques In this chapter you continue exploring the C language by looking at a few bits and pieces that haven t quite fit in elsewhere. This isn t to say that these techniques aren t useful just that they don t fall under any of the headings you ve worked through so far. Specifically you will look at the following The operator and the global namespace qualifier Custom exceptions and exception recommendations Events Anonymous methods You also make some final modifications to the CardLib code that you ve been building in the last few chapters and even use CardLib to create a card game. The Operator and the Global Namespace Qualifier The operator provides an alternative way to access types in namespaces. This may be necessary if you want to use a namespace alias and there is ambiguity between the alias and the actual namespace hierarchy. If that s the case then the namespace hierarchy is given priority over the namespace alias. To see what this means consider the following code using MyNamespaceAlias namespace MyRootNamespace namespace MyNamespaceAlias

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
198    329    1    28-04-2024
Đã 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.