Intro Week 6

From IAM MediaWiki Create Change
Jump to: navigation, search

Review Arrays

Review Generic Lists

List<int> scores = new List<int>();  //A list of ints 

List<string> names = new List<string>(); //A list of strings

//add some ints to the scores list

//Add some names to the names list
names.Add("Uncle Eddie");

foreach(string name in names)

Simple arrays and multidimensional arrays

OOP Arrays


Structures -struct are composed of several pieces of data that can be of different types.

struct student
public int oasis id;
public string name;
public double GPA;
struct player
public int playerID;
public string playerName;
public difficulty playerLevel;
In class demo coins
Quarter class
Coin class


Function help with code reuse. If your going to use it more than once make it into a funtions. syntax simple

[access-modifier] return type indentifier ( [parateters] )
    //some code

public : mean that this method can be called from anywhere else in the program

static means that


public static string Hello ()
    return "Hello ";

public static string HelloToName (string Name)
    return "Hello " + Name;

Calling a finction in c#

string firstHello, jeffHello;   //declare some strings
firstHello = Hello();   //call the function Hello
jeffHello = HelloToName("Jeff");   //call the function HelloToName

Console Example /infod/jeff/classSource/class3/function.cs - source

Hello World!
Hello Jeff
Hello Marge



Home work

Sweet card program have it for super freeeee as in free beer

Write a csharp program that uses a coin struct to make a coin collection

start with

12 quarters

22 dimes

5 nickels

and 174 pennies.

After you have made the coin collection (Array or List). Write a method that can calculate the value of the collection.

Bonus write a csharp program that can make correct change given an amount of money.

ie type in 1.08 and it will give back a coin collection of

4 quarters

1 nickel

3 pennies