Chapter 05 - An Introduction To Object Oriented Programming...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
An Introduction To Object Oriented Programming Chapter 5 Using Arrays
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Microsoft Visual C# 2008, Third Edition 2 Declaring an Array and Assigning Values to Array Elements Array List of data items that all have the same data type and the same name Each item is distinguished from the others by an index Declaring and creating an array double[] sales; sales = new double[20]; new operator Used to create objects You can change the size of an array
Background image of page 2
Microsoft Visual C# 2008, Third Edition 3 Declaring an Array and Assigning Values to Array Elements (continued) Array element Each object in an array Subscript (or index ) Integer contained within square brackets that indicates the position of one of an array’s elements Array’s elements are numbered beginning with 0 “Off by one” error Occurs when you forget that the first element in an array is element 0
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Microsoft Visual C# 2008, Third Edition 4 Declaring an Array and Assigning Values to Array Elements (continued)
Background image of page 4
Microsoft Visual C# 2008, Third Edition 5 Declaring an Array and Assigning Values to Array Elements (continued) Assigning a value to an array element sales[0] = 2100.00; Printing an element value Console.WriteLine(sales[19]);
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Microsoft Visual C# 2008, Third Edition 6 Initializing an Array In C#, arrays are objects Arrays are instances of a class named System.Array Initializing objects Numeric fields: 0 Character fields: ‘\u0000’ or null bool fields: false Initializer list List of values provided for an array
Background image of page 6
Microsoft Visual C# 2008, Third Edition 7 Initializing an Array (continued) Initializer list examples int[] myScores = new int[5] {100, 76, 88, 100, 90}; int[] myScores = new int[] {100, 76, 88, 100, 90}; int[] myScores = {100, 76, 88, 100, 90};
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/29/2010 for the course BUSI 12345 taught by Professor Mm during the Spring '10 term at Prince Sultan University.

Page1 / 34

Chapter 05 - An Introduction To Object Oriented Programming...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online