tailieunhanh - accelerated c# 2010 trey nash phần 6
Tham khảo tài liệu 'accelerated c# 2010 trey nash phần 6', 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 9 ARRAYS COLLECTION TYPES AND ITERATORS Development Team foreach var employee in developmentTeam t Under the covers the compiler generates a fair amount of code to help you out here. For each item in the collection initialization list the compiler generates a call to the collection s Add method. Notice that I have also used the new object initializer syntax to initialize each of the instances in the initializer list. As I ve mentioned the collection type must implement ICollection T or implement IEnumerable T and a public Add method. If it does not you will receive compile-time errors. Additionally the collection must implement only one specialization of ICollection T that is it can only implement ICollection T for one type T. And finally each item in the collection initialization list must be implicitly convertible to the type T. Summary In this chapter I gave a brief overview of how arrays work in the CLR and in C in preparation for the discussion of generic collection types. After reviewing the generic collection types defined in I covered efficiency and usage concerns and introduced you to the useful types defined in . I then turned the spotlight on enumerators and showed you how to create effective enumerators efficiently by employing iterator yield blocks added in the C language. Finally I showed you the syntax added in C that streamlines initializing a collection at instantiation time. Although this chapter didn t delve into the minute details of each of the collection types after reading the chapter you should be effectively armed with the information you need to make informed choices about which generic collection types to use and when. I encourage you to reference the MSDN documentation often for all of the finer details regarding the APIs for the collection types. In the next chapter I cover delegates anonymous methods and events. .
đang nạp các trang xem trước