Intro Week 6

esse quam videri
Revision as of 04:09, 2 March 2010 by Jeff (talk | contribs) (Review Arrays)
Jump to: navigation, search

Review Arrays

Review Generic Lists

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

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

Simple arrays and multidimensional arrays

OOP Arrays

Struct

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

<csharp> struct student { public int oasis id; public string name; public double GPA; } </csharp> <csharp> struct player { public int playerID; public string playerName; public difficulty playerLevel; } </csharp>

In class demo coins
Quarter class
*Mint
*Year
Coin class
*Mint
*Year
*Value

Functions/Methods

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

}

access-modifiers
public
private
protected
internal
protected internal
more on these next week.

Defining

<csharp>string Hello () {

   return "Hello ";

}

string HelloToName (string Name) {

   return "Hello " + Name;

}</csharp>

Calling a finction in c#

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

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

C:\User\csharp>csc function.cs
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.


C:\User\csharp>function.cs

C:\User\csharp>function.exe
Hello World!
Hello
Hello Jeff
Hello Marge

C:\User\csharp>

function.cs

Passing variable into a function/method passes be instance. Variables passed by instance do not actually pass in the original variable rather a copy or new instance of the variable is passed. It you want to pass in the actual variable you need to pass be referance Examples of passesing by instamce and passing by refecnce... /infod/jeff/classSource/class3/instanceReference.aspx - Source