Objectives: Arrays and Collections
Objectives: Arrays and Collections
Objectives
Chapter 8
Arrays and Collections
McGraw-Hill
8-2
Copyr ight 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Array Terms
Single-Dimension Arrays
Element
Must be an integer
Boundaries
8-3
8-4
Subscripts
Array Example
nameString Array
(0)
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
Janet Baker
George Lee
Sue Li
Samuel Hoosier
Sandra Weeks
William Macy
Andy Harrison
Ken Ford
Denny Franks
Shawn James
8-5
8-6
7/31/2014
8-8
Valid Subscripts
8-9
8-10
8-11
8-12
7/31/2014
Structures
8-14
Structure SalesDetail
Dim SaleDecimal () As Decimal
End Structure
8-15
8-16
OfficeEmployee.LastNameString
OfficeEmployee.HireDate
InventoryP roduct(indexInteger).DescriptionString
InventoryP roduct(indexInteger).QuantityInteger
InventoryP roduct(indexInteger).P riceDecimal
8-17
8-18
7/31/2014
8-20
Table Look up
8-21
8-22
8-23
8-24
7/31/2014
IndexInteger = GroupListBox.SelectedIndex
If IndexInteger <> 1 Then
8-25
8-26
Multidimensional Arrays
SaleInteger = Integer.Parse(SaleTextBox.Text)
TotalInteger(IndexInteger) += SaleInteger
' Clear the screen fields.
GroupListBox.SelectedIndex = 1
SaleTextBox.Text = ""
Else
MessageBox.Show("Select a group number from
the list.", "Data Entry Error",
MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If
8-27
8-28
8-29
(0, 0)
James
(0, 1)
Mary
(0, 2)
Sammie
(0, 3)
Sean
(1, 0)
Tom
(1, 1)
Lee
(1, 2)
Leon
(1, 3)
Larry
(2, 0)
Maria
(2, 1)
Margaret
(2, 2)
Jill
(2, 3)
John
8-30
7/31/2014
Initializing/Reinitializing
8-31
8-32
8-33
8-34
Table Look up
8-35
8-36
7/31/2014
.NET Collections
SortedList Collection
related data.
More sophisticated than arrays
Example collection types
index.
ArrayList
SortedList
Queue
Stack
handling.
8-37
8-38
8-39