Download presentation
Presentation is loading. Please wait.
1
Arrays and Collections
One dimensional array Two or multiple dimensional array Collections Standard collection: ArrayList Generic collection: LinkedList The individual values of an array are boxed if they are value types. Array indices are zero based. The array type has methods for accessing and manipulating the contents of the array. All operations on the array are bound checked. Any access beyond the maximum size of the array results in an exception - "Index out of range". Arrays get allocated only on the heap; hence an array of value types gets all its values boxed to the heap.
2
Array in C++/CLI Array, element, index(or subscript)
array<int> ^ a = gcnew array<int>(12); array<int> ^ a = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; a[0], a[1],…, and a[11] a->Length array<String ^> ^d = {“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”}; int main(array<System::String ^> ^args) {}
3
Array in C++/CLI Multi-dimensional Array
array<int, 2> ^ b = gcnew array<int, 2>(4,3); array<int, 2> ^ b = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {0, 1, 2}}; b[0,0], b[0,1],…, b[3,2]; b->Rank, b->GetLength(0), b->GetLength(1) Parentheses Square bracket Angle bracket Curly Brace
4
Collections in C++/CLI
ArrayList (System::Collections Namespace) Index-based Constant-time random access consecutive Dynamically growing arrays, re-sizeable LinkedList (System::Collections::Generic Namespace) Traverse the list to find the proper node Dis-contiguous An array list is a collection of one or more (usually more) elements arranged in memory in a consecutive fashion, accessed as one indexable entity. A linked list is a collection of one or more (usually more) elements arranged in memory in a (usually) dis-contiguous fashion, using pointers contained in each element that point to the next element in the list.
5
Collections in C++/CLI
ArrayList ^ list1 = gcnew ArrayList(); Property: Count Methods: [], Add, AddRange, Insert, InsertRange, Remove, RemoveAt, RemoveRange, Clear, Reverse, Sort, Contains, IndexOf
6
Collections in C++/CLI
LinkedList<String^> ^list2 = gcnew LinkedList<String^>(); LinkedListNode<String^> ^cur; cur->Value, cur->Next; cur->Previous (nullptr) Property: Count, First, Last Methods: AddFirst, AddLast, AddBefore, AddAfter, RemoveFirst, RemoveLast, Remove, Clear, Find,
7
Example: testArrayCollection.cpp
Single and two dimensional arrays Type of string reference, fixed length
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.