Wk10_arrays_01 - Programming I Arrays Narendra Pershad...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming I Arrays Narendra Pershad Winter 2016
Image of page 1

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

View Full Document Right Arrow Icon
Topics Declare an array and assign values to array elements Access array elements Search an array using a loop Use the BinarySearch() , Sort() , and Reverse() methods Use multidimensional arrays Shortcuts in creating arrays
Image of page 2
What is an array? Multi-value variable A set of values that shares the same name Midterm marks of all the students in COMP100 Each value is called an item or element The elements are referenced by using a subscript Subscripts are integer and starts at 0 Used extensively in legacy code The size of Array can change, but it is a potentially expensive operation
Image of page 3

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

View Full Document Right Arrow Icon
Using arrays Declaration int [] marks; char [] vowels; Allocating storage marks = new int [38]; vowels = new char [5];
Image of page 4
Accessing elements Setting values marks[0] = 75; //assigns 75 to the first item marks[1] = 91; //assigns 91 to the second item vowels[0] = 'a' ; vowels[1] = 'e' ; vowels[2] = 'i' ; vowels[3] = 'o' ; vowels[4] = 'u' ; Getting value Console .WriteLine(marks[0]); //outputs the first item Console .WriteLine(marks); //gibberish
Image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern