-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassingArrays.cs
58 lines (50 loc) · 1.47 KB
/
PassingArrays.cs
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
using System;
namespace Week14Repetition.Arrays
{
class Program
{
static void Main()
{
int[] array = new int[] { 1, 1, 2, 3, 5 };
//PrintArray(array, true, "ChangeA");
ChangeA(array);
//PrintArray(array, false, "ChangeA");
//PrintArray(array, true, "ChangeB");
ChangeB(array);
//PrintArray(array, false, "ChangeB");
//PrintArray(array, true, "ChangeC");
ChangeC(array);
//PrintArray(array, false, "ChangeC");
//PrintArray(array, true, "ChangeD");
ChangeD(array);
//PrintArray(array, false, "ChangeD");
}
public static void ChangeA(int[] array)
{
array[3] = 24;
}
public static void ChangeB(int[] array)
{
int[] myArray = array;
myArray[4] = 42;
}
public static void ChangeC(int[] array)
{
array[0] = array[2];
}
public static void ChangeD(int[] array)
{
array = new int[5];
}
// Ignore this method
public static void PrintArray(int[] array, bool before, string method)
{
Console.WriteLine(
"{0} {1}: [{2}]",
method,
before ? "before" :"after",
string.Join(", ", array)
);
}
}
}