Skip to content

Commit fcfc88a

Browse files
author
Oyvind Timian Dokk Husveg
committed
Oyvind Husveg
1 parent 337b13b commit fcfc88a

File tree

1 file changed

+10
-12
lines changed
  • csharp-fundamentals-arrays.Main

1 file changed

+10
-12
lines changed

csharp-fundamentals-arrays.Main/Core.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ public void example()
2222
// WRITE YOUR CODE BETWEEN THIS LINE...
2323
Console.WriteLine("Hello");
2424
// ... AND THIS LINE
25-
}
25+
}
2626

2727
public int[] one()
2828
{
29-
throw new NotImplementedException();
3029
int[] numbers = { 42, 13, 17, 91 };
3130

3231
// 1. Values contained in an array are each stored at a unique numeric index, starting from 0 ascending in order.
3332
// E.g. The first value is at index 0, the second at index 1, the third at index 3.
3433
// Using an index, change the number 17 in the numbers array to 68
3534
// WRITE YOUR CODE BETWEEN THIS LINE...
3635

37-
36+
numbers[2] = 68;
3837

3938
// ... AND THIS LINE
4039

@@ -43,14 +42,13 @@ public int[] one()
4342

4443
public String two()
4544
{
46-
throw new NotImplementedException();
4745
String[] teachers = { "Nathan", "Ed", "Dave", "Carlo", "Lewis", "Jules", "John", "Chris", "Nigel" };
4846

4947
//TODO: 2. Using an array index, change the value of the teacher variable below to be the fourth
5048
// teacher contained in the teachers array
5149
// WRITE YOUR CODE BETWEEN THIS LINE...
5250

53-
String teacher = "";
51+
String teacher = teachers[3];
5452

5553
// ... AND THIS LINE
5654

@@ -59,40 +57,40 @@ public String two()
5957

6058
public String[] three()
6159
{
62-
throw new NotImplementedException();
6360
//TODO: 3. Create a string array named cars that contains three names of car manufacturers: Audi, BMW and Dodge
6461
// WRITE YOUR CODE BETWEEN THIS LINE...
6562

66-
63+
string[] cars = ["Audi", "BMW", "Dodge"];
6764

6865
// ... AND THIS LINE
6966

70-
//return cars;
67+
return cars;
7168
}
7269

7370
public int four()
7471
{
75-
throw new NotImplementedException();
7672
int[] numbers = { 42, 13, 17, 91 };
7773

7874
// TODO 4. Using array indices, set the value of the result variable below to the sum of every number in the numbers array
7975
// WRITE YOUR CODE BETWEEN THIS LINE...
8076

8177
int result = 0;
8278

79+
foreach (int i in numbers) {
80+
result = result + i;
81+
}
82+
8383
// ... AND THIS LINE
8484

8585
return result;
8686
}
8787

8888
public float[] five()
8989
{
90-
throw new NotImplementedException();
9190
//TODO: 5. Create an array called floats that contains 3 floating point numbers: 9.62, 23.17 and 3.14
9291
// WRITE YOUR CODE BETWEEN THIS LINE...
9392

94-
float[] floats;
95-
93+
float[] floats = [9.62f, 23.17f, 3.14f];
9694

9795
// ... AND THIS LINE
9896

0 commit comments

Comments
 (0)