-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (55 loc) · 2.34 KB
/
Program.cs
File metadata and controls
71 lines (55 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
namespace _6Methods
{
class Program
{
//METHOD BASICS
//Go to the class Methods.cs to start this lesson.
public static void Main(string[] args)
{
Methods myMethods = new Methods();
var result = myMethods.GetHello("Jen"); //Method invocation
Console.WriteLine(result);
myMethods.DoSomething(); //Method has "void" return type, so nothing will be returned.
//PARAMETERS
Parameters myParameters = new Parameters();
int value1 = 5; //Used as arguments below
int value2 = 16;
int sum = myParameters.Add(value1, value2); //Sum == 21
Console.WriteLine(sum);
//OUT KEYWORD
//Occassionally we want to pass out multiple values from a single method.
//We can pass parameters using the *out* keyword to specify this.
string intString = "5";
bool hasValue = int.TryParse(intString, out int intResult); //Result is now 5
Console.WriteLine(hasValue.ToString());
if (hasValue)
{
Console.WriteLine(intResult);
}
//REF KEYWORD
int total = 17;
int nextNumber = 2;
myParameters.Sum(ref total, nextNumber); //total is now 19
myParameters.Sum(ref total, 6); //total is now 25
Console.WriteLine(total);
//IN KEYWORD
double pi = 3.14159;
var circumference = myParameters.GetCircumference(4.5, pi);
Console.WriteLine(circumference);
//PARAMS KEYWORD
var totalPrice = myParameters.GetTotalPriceForSeats(90, 91, 92, 93, 94);
Console.WriteLine(totalPrice); //460
//OPTIONAL PARAMETERS
int byOne = myParameters.Increment(10); //11
Console.WriteLine(byOne);
int byFive = myParameters.Increment(10, 5); //15
Console.WriteLine(byFive);
//NAMED ARGUMENTS
//The parameter "height" is listed first, but by using the parameter names
//as labels for the arguments, we can pass them out of order.
var volume = myParameters.GetPyramidVolume(baseArea: 12, height: 4);
Console.WriteLine("Volume is " + volume.ToString());
}
}
}