Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Cis166 final review c#


Published on

Published in: Education
  • Be the first to comment

  • Be the first to like this

Cis166 final review c#

  1. 1. CIS-166 Final <ul><li>Open book, open notes, open computer </li></ul><ul><li>100 points </li></ul><ul><li>True/false, multiple choice, fill-in, short answer </li></ul><ul><li>Emphasis on material since midterm </li></ul>
  2. 2. Arrays <ul><li>List or series of values all referenced by the same name </li></ul><ul><li>Use an array to keep a series of variables for later processing such as </li></ul><ul><ul><li>Reordering </li></ul></ul><ul><ul><li>Calculating </li></ul></ul><ul><ul><li>Printing </li></ul></ul>
  3. 3. Array Terms <ul><li>Element </li></ul><ul><ul><li>Individual item in the array </li></ul></ul><ul><li>Index (or subscript) </li></ul><ul><ul><li>Zero based number used to reference the specific elements in the array </li></ul></ul><ul><ul><li>Must be an integer </li></ul></ul><ul><li>Boundaries </li></ul><ul><ul><li>Lower Subscript, 0 by default </li></ul></ul><ul><ul><li>Upper Subscript </li></ul></ul>
  4. 4. Simple Array Example studentNames 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
  5. 5. Dim Statement for Arrays Default Values <ul><li>string[] strName = string[4] </li></ul><ul><li>Results in an array of 4 elements: strName(0), strName(1), </li></ul><ul><li>strName(2), strName(3) </li></ul><ul><li>decimal[] decBalance = new decimal[100] </li></ul><ul><li>Results in an array of 100 elements: decBalance(0), . . . , decBalance(99) </li></ul>
  6. 6. Dim Statement for Arrays Assigned Values <ul><li>string[] departments = {&quot;ACT&quot;, &quot;MKT&quot;, &quot;HR&quot;} </li></ul><ul><li>Results in an array with 3 elements, each with a value, departments[0] is “ACT” </li></ul><ul><li>Integer[] intActCode = {10, 20, 30, 40} </li></ul><ul><li>Results in an array with 4 elements, each with a number stored </li></ul>
  7. 7. Referencing Array Elements <ul><li>Use the Index(es) of the Element </li></ul>Sam Smith Jill Creech Paul Fry Rich Wells strName[0] : &quot;Sam Smith&quot; strName[1] : &quot;Jill Creech&quot; strName[2] : &quot;Paul Fry&quot; strName[3] : &quot;Rich Wells&quot; strName(row) (0) (1) (2) (3)
  8. 8. Working with Arrays <ul><li>Use Loops to reference each element in the array </li></ul><ul><ul><li>For / Next </li></ul></ul><ul><ul><li>For Each / Next </li></ul></ul>
  9. 9. For Next Loop <ul><li>Assume strNames[10] already declared </li></ul><ul><li>integer intCounter, intEnd </li></ul><ul><li>intEnd = strNames.GetUpperBound(0) </li></ul><ul><li>For (intCounter = 0; intcounter<=intEnd; intCounter++) </li></ul><ul><ul><li>{Console.Writeline(strNames[intCounter])} </li></ul></ul>
  10. 10. For Each Loop <ul><li>Assume strNames[10] already declared </li></ul><ul><li>foreach (string Item in strNames) </li></ul><ul><ul><li>{Console.Writeline(Item)] </li></ul></ul>
  11. 11. Object Terminology Review <ul><li>Object - like a noun, a thing </li></ul><ul><ul><li>An object is based on a class </li></ul></ul><ul><li>Properties - like an adjective, characteristics of object </li></ul><ul><li>Methods - like a verb, an action or behavior, something the object can do </li></ul><ul><li>Events - object response to user action or other events </li></ul>
  12. 12. Polymorphism <ul><li>Overloading: Argument type determines which version of a method is used </li></ul><ul><ul><li>Example: MessageBox.Show method </li></ul></ul><ul><li>Overriding: Refers to a class that has the same method name as its base class </li></ul><ul><ul><li>Method in subclass takes precedence </li></ul></ul>
  13. 13. Specifying a Namespace <ul><li>Namespaces are used in .Net to organize classes and source files </li></ul><ul><li>When referring to classes in a different namespace </li></ul><ul><ul><li>Write out the entire namespace </li></ul></ul><ul><ul><li>Add an Imports Statement to include the namespace </li></ul></ul>Using System.Windows.Forms.Form Name of the Class Namespace
  14. 14. Instance versus Static Variables <ul><li>Instance variables or properties use a separate memory location for each instance of the object </li></ul><ul><li>Static variables or properties use a single memory location that is available for ALL objects of a class </li></ul><ul><ul><li>Can be accessed without instantiating an object of the class </li></ul></ul><ul><ul><li>Use the Static keyword to create </li></ul></ul>Static Methods can also be created
  15. 15. Constructors and Destructors <ul><li>Constructor: Method that automatically executes when an object is instantiated </li></ul><ul><ul><li>Create by writing a procedure using the Class Name, followed by any arguments </li></ul></ul><ul><li>Destructor: Method that automatically executes when an object is destroyed </li></ul><ul><ul><li>Microsoft discourages use of in .Net </li></ul></ul>
  16. 16. Collections <ul><li>Group of objects </li></ul><ul><ul><li>Can be strongly typed: all objects based on the same class </li></ul></ul><ul><li>Similar to an array </li></ul><ul><ul><li>Collection expands and contracts automatically </li></ul></ul><ul><li>Have common properties and methods </li></ul><ul><ul><li>Add, Remove, Count, Item (Indexer) </li></ul></ul>
  17. 17. Item Property <ul><li>Typically default property for a collection </li></ul><ul><ul><li>Refer to collection object, followed by location (in []) </li></ul></ul><ul><li>Returns a member of the group </li></ul><ul><ul><li>Typically based on location, but can use other values </li></ul></ul><ul><ul><li>Data type depends on the type of objects the collection manages </li></ul></ul>
  18. 18. Text Data Files <ul><li>Actual data stored in files on disk device </li></ul><ul><li>File ==> Entire collection of data of data </li></ul><ul><li>Records ==> Rows or lines, one per entity </li></ul><ul><li>Fields ==> Data elements within row </li></ul>
  19. 19. Text File Handling <ul><li>A Stream is designed to transfer a series of bytes from one location to another </li></ul><ul><li>Streams are objects that have properties and methods </li></ul><ul><li>Found in the System.IO namespace </li></ul><ul><li>File handling projects usually contain an Imports statement before the statement declaring the form's class </li></ul>
  20. 20. Writing Data Files <ul><li>Declare a new StreamWriter object </li></ul><ul><li>Use StreamWriter's WriteLine method </li></ul><ul><li>Call StreamWriter's Close method </li></ul>
  21. 21. Write and WriteLine Methods <ul><li>Write Method: Places items consecutively in the file with no separator </li></ul><ul><li>WriteLine Method: Places an Enter (carriage return) between records </li></ul>
  22. 22. Reading Files <ul><li>Declare a new StreamReader object </li></ul><ul><ul><li>File must exist! </li></ul></ul><ul><li>Use StreamReader's ReadLine method </li></ul><ul><ul><li>Loop to retrieve multiple records </li></ul></ul><ul><li>Call StreamReader's Close method </li></ul>
  23. 23. ReadLine Method <ul><li>Use to read previously saved data </li></ul><ul><li>Each time it executes, it reads the next line of data </li></ul><ul><li>Always assign the value from the read to a location, such as a label, text box, or string variable </li></ul>
  24. 24. Checking for End of File <ul><li>Use StreamReader's Peek Method </li></ul><ul><li>Peek looks at the next element without actually reading it </li></ul><ul><li>If you Peek beyond the last element the value returned is -1 </li></ul>