Difference between revisions of "Intro Week 6"
(→Functions/Methods) |
(→Functions/Methods) |
||
Line 73: | Line 73: | ||
access-modifiers<br> | access-modifiers<br> | ||
public : mean that this method can be called from anywhere else in the program<br> | public : mean that this method can be called from anywhere else in the program<br> | ||
− | + | Static | |
+ | :static means that | ||
Defining | Defining |
Revision as of 15:21, 2 March 2010
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
//add some ints to the scores list scores.Add(100); scores.Add(7);
//Add some names to the names list names.Add("Jeff"); names.Add("Uncle Eddie");
foreach(string name in names) {
Console.WriteLine(name);
}
</csharp>
Simple arrays and multidimensional 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 : mean that this method can be called from anywhere else in the program
Static
- static means that
Defining
<csharp>public static string Hello () {
return "Hello ";
}
public static 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
Hello World! Hello Hello Jeff Hello Marge C:\User\csharp>