Lecture Windows programming: Chapter 6 - Châu Thị Bảo Hà

Chapter 6 of lecture Windows programming introduce about Arrays - collections. In this chapter you will be learn contents: Declaring and Allocating arrays, initializing an array, properties – methods of an array, foreach loops, namespace, ArrayList class,. | Arrays - Collections Chapter 6 Ebook: Beginning Visual C# 2010, part 1, chapter 5, 11 Reference: CSharp How to Program Contents Arrays Collections Slide 2 Arrays () Declaring and Allocating arrays Initializing an array Properties – Methods of an array foreach loops Array parameter Multidimensional arrays Slide 3 Declaring and Allocating arrays Example: int[] a = new int[12]; bool[] b = new bool[100]; Circle[] listCir = new Circle[5]; // reference types When arrays are allocated, the elements are initialized: zero for the numeric data-type false for bool variables null for reference types DataType[ ] ArrayName; // declare array ArrayName = new DataType[size]; // allocate array // declare and allocate array DataType[ ] ArrayName = new DataType[size]; Arrays are indexed lists of variables stored in a single array type variable Slide 4 Declaring: specifies the type of the elements of the array Allocating: specifies the number of elements in the array, using new operator to allocate dynamically Arrays are allocated with new because arrays are objects and all objects must be created with new. C# includes built-in value types and reference types. The built-in value types are: * the integral types (sbyte, byte, char, short, ushort, int, uint, long and ulong), * the floating-point types (float and double) and the types decimal and bool. The built-in reference types are string and object. Initializing an array Arrays can be declared, allocated, initialized in a statement int[] myIntArray = new int[5] { 2, 4, 6, 8, 10}; Allocate space for the array – number of elements in initializer list determines the size of array int[] myIntArray = { 2, 4, 6, 8, 10}; Slide 5 Properties - Methods of an array returns size of array (int index) array_name[int index] returns an object at position index (object value, int index) array_name[int index] = value modifies an object at position index Slide 6 foreach Loops Example: foreach | Arrays - Collections Chapter 6 Ebook: Beginning Visual C# 2010, part 1, chapter 5, 11 Reference: CSharp How to Program Contents Arrays Collections Slide 2 Arrays () Declaring and Allocating arrays Initializing an array Properties – Methods of an array foreach loops Array parameter Multidimensional arrays Slide 3 Declaring and Allocating arrays Example: int[] a = new int[12]; bool[] b = new bool[100]; Circle[] listCir = new Circle[5]; // reference types When arrays are allocated, the elements are initialized: zero for the numeric data-type false for bool variables null for reference types DataType[ ] ArrayName; // declare array ArrayName = new DataType[size]; // allocate array // declare and allocate array DataType[ ] ArrayName = new DataType[size]; Arrays are indexed lists of variables stored in a single array type variable Slide 4 Declaring: specifies the type of the elements of the array Allocating: specifies the number of elements in the array, using new operator to allocate .

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.