+ All Categories
Home > Education > Cis166 Final Review C#

Cis166 Final Review C#

Date post: 14-May-2015
Category:
Upload: randy-riness-south-puget-sound-community-college
View: 584 times
Download: 1 times
Share this document with a friend
Popular Tags:
24
CIS-166 Final CIS-166 Final Open book, open notes, open computer 100 points True/false, multiple choice, fill-in, short answer Emphasis on material since midterm
Transcript
Page 1: Cis166 Final Review C#

CIS-166 FinalCIS-166 FinalOpen book, open notes, open

computer100 pointsTrue/false, multiple choice, fill-in,

short answerEmphasis on material since

midterm

Page 2: Cis166 Final Review C#

ArraysArraysList or series of values all

referenced by the same nameUse an array to keep a series of

variables for later processing such as ◦Reordering◦Calculating◦Printing

Page 3: Cis166 Final Review C#

Array TermsArray Terms

Element◦Individual item in the array

Index (or subscript)◦Zero based Zero based number used to

reference the specific elements in the array

◦Must be an integerBoundaries

◦Lower Subscript, 0 by default◦Upper Subscript

Page 4: Cis166 Final Review C#

Simple Array ExampleSimple Array Example

studentNames Array(0)(1)(2)(3)(4)(5)(6)(7)(8)(9)

Janet BakerGeorge LeeSue LiSamuel HoosierSandra WeeksWilliam MacyAndy HarrisonKen FordDenny FranksShawn James

Page 5: Cis166 Final Review C#

Dim Statement for ArraysDim Statement for ArraysDefault ValuesDefault Values

string[] strName = string[4]Results in an array of 4 elements:

strName(0), strName(1), strName(2), strName(3)

decimal[] decBalance= new decimal[100]Results in an array of 100 elements:

decBalance(0), . . . , decBalance(99)

Page 6: Cis166 Final Review C#

Dim Statement for ArraysDim Statement for ArraysAssigned ValuesAssigned Values

string[] departments = {"ACT", "MKT", "HR"}Results in an array with 3 elements, each with a value, departments[0] is “ACT”

Integer[] intActCode = {10, 20, 30, 40}Results in an array with 4 elements, each with a number stored

Page 7: Cis166 Final Review C#

Referencing Array Referencing Array ElementsElementsUse the Index(es) of the Element

strName(row)(0)(1)(2)(3)

Sam SmithJill CreechPaul FryRich Wells

strName[0] : "Sam Smith"strName[1] : "Jill Creech"strName[2] : "Paul Fry"strName[3] : "Rich Wells"

Page 8: Cis166 Final Review C#

Working with ArraysWorking with ArraysUse Loops to reference each

element in the array◦For / Next ◦For Each / Next

Page 9: Cis166 Final Review C#

For Next LoopFor Next Loop

Assume strNames[10] already declared

integer intCounter, intEndintEnd = strNames.GetUpperBound(0)For (intCounter = 0; intcounter<=intEnd;

intCounter++){Console.Writeline(strNames[intCounter]

)}

Page 10: Cis166 Final Review C#

For Each LoopFor Each Loop

Assume strNames[10] already declared

foreach (string Item in strNames){Console.Writeline(Item)]

Page 11: Cis166 Final Review C#

Object Terminology Object Terminology ReviewReviewObject - like a noun, a thing

◦An object is based on a classProperties - like an adjective,

characteristics of objectMethods - like a verb, an action

or behavior, something the object can do

Events - object response to user action or other events

Page 12: Cis166 Final Review C#

PolymorphismPolymorphismOverloading: Argument type

determines which version of a method is used◦Example: MessageBox.Show method

Overriding: Refers to a class that has the same method name as its base class◦Method in subclass takes precedence

Page 13: Cis166 Final Review C#

Specifying a NamespaceSpecifying a NamespaceNamespaces are used in .Net to

organize classes and source filesWhen referring to classes in a

different namespace◦ Write out the entire namespace◦ Add an Imports Statement to include the

namespaceUsing System.Windows.Forms.Form

Name of the ClassNamespace

Page 14: Cis166 Final Review C#

Instance versus Static Instance versus Static VariablesVariablesInstance variables or properties

use a separate memory location for each instance of the object

Static variables or properties use a single memory location that is available for ALL objects of a class◦Can be accessed without

instantiating an object of the class◦Use the Static keyword to create

Static Methods can also be created

Page 15: Cis166 Final Review C#

Constructors and Constructors and DestructorsDestructorsConstructor: Method that

automatically executes when an object is instantiated◦Create by writing a procedure using

the Class Name, followed by any arguments

Destructor: Method that automatically executes when an object is destroyed◦Microsoft discourages use of in .Net

Page 16: Cis166 Final Review C#

CollectionsCollectionsGroup of objects

◦Can be strongly typed: all objects based on the same class

Similar to an array◦Collection expands and contracts

automaticallyHave common properties and

methods◦Add, Remove, Count, Item (Indexer)

Page 17: Cis166 Final Review C#

Item PropertyItem PropertyTypically default property for a

collection◦Refer to collection object, followed

by location (in [])Returns a member of the group

◦Typically based on location, but can use other values

◦Data type depends on the type of objects the collection manages

Page 18: Cis166 Final Review C#

Text Data FilesText Data Files

Actual data stored in files on disk device

File: Entire collection of dataRecords: Rows or lines, one

per entityFields: Data elements (values)

within a row

Page 19: Cis166 Final Review C#

Text File HandlingText File Handling

A Stream is designed to transfer a seriesof bytes from one location to another

Streams are objects that have properties and methods

Found in the System.IO namespaceFile handling projects usually

contain an Imports statement before the statement declaring the form's class

Page 20: Cis166 Final Review C#

Writing Data FilesWriting Data FilesDeclare a new StreamWriter

objectUse StreamWriter's WriteLine method

Call StreamWriter's Close method

Page 21: Cis166 Final Review C#

Write and WriteLine Write and WriteLine MethodsMethodsWrite Method: Places items

consecutively in the file with no separator

WriteLine Method: Places an Enter (carriage return) between records

Page 22: Cis166 Final Review C#

Reading FilesReading FilesDeclare a new StreamReader

object◦File must exist!

Use StreamReader's ReadLine method◦Loop to retrieve multiple records

Call StreamReader's Close method

Page 23: Cis166 Final Review C#

ReadLine MethodReadLine Method

Use to read previously saved dataEach time it executes, it reads the

next line of dataAlways assign the value from the

read to a location, such as a label, text box, or string variable

Page 24: Cis166 Final Review C#

Checking for End of FileChecking for End of FileUse StreamReader's Peek Method

Peek looks at the next element without actually reading it

If you Peek beyond the last element the value returned is -1


Recommended