Chương 6: Array, Collection Types, and Iterators

This chapter covers the various array and collection types available in C#. You can create two types of multidimensional arrays, as well as your own collection types while utilizing collection-utility classes. | Hoang Anh Viet VietHA@ HaNoi University of Technology Chapter 6. Arrays, Collection Types, and Iterators 3. Data Types 2008 © 2008 Microsoft Objectives “This chapter covers the various array and collection types available in C#. You can create two types of multidimensional arrays, as well as your own collection types while utilizing collection-utility classes. You’ll see how to define forward, reverse, and bidirectional iterators using the new iterator syntax introduced in C# , so that your collection types will work well with foreach statements.” 3. Data Types 2008 © 2008 Microsoft Roadmap . Introduction to Arrays . Multidimentional Rectangular Arrays . Multidimentional Jagged Arrays . Collection Types . Iterators . Collection Initializers . Introduction to Arrays Overview Implicitly Typed Arrays Type Convertibility and Covariance Arrays As Parameters (and Return Values) The Base Class Overview An array is a set of data items, accessed using an numerical index An array is a group of contiguous memory locations that all have the same name and type Arrays are reference types, and the memory for the array is allocated on the managed heap. Array Initialization Syntax: Example: 100 200 300 myInts[0] myInts[1] myInts[2] Position number of the element within array myInts static void SimpleArrays() { ("=> Simple Array Creation."); // Create and fill an array of 3 Integers int[] myInts = new int[3]; myInts[0] = 100; myInts[1] = 200; myInts[2] = 300; // Now print each value. foreach(int i in myInts) (i); (); } Figure 6-1: Array of reference types versus value types Implicitly Typed Arrays C# introduces an abbreviated way of initializing arrays when the type of the array can be inferred at runtime When the compiler is presented with multiple types within the initialization list of an implicitly typed array, it determines a type | Hoang Anh Viet VietHA@ HaNoi University of Technology Chapter 6. Arrays, Collection Types, and Iterators 3. Data Types 2008 © 2008 Microsoft Objectives “This chapter covers the various array and collection types available in C#. You can create two types of multidimensional arrays, as well as your own collection types while utilizing collection-utility classes. You’ll see how to define forward, reverse, and bidirectional iterators using the new iterator syntax introduced in C# , so that your collection types will work well with foreach statements.” 3. Data Types 2008 © 2008 Microsoft Roadmap . Introduction to Arrays . Multidimentional Rectangular Arrays . Multidimentional Jagged Arrays . Collection Types . Iterators . Collection Initializers . Introduction to Arrays Overview Implicitly Typed Arrays Type Convertibility and Covariance Arrays As Parameters (and Return Values) The Base Class Overview An

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
Đã 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.