From 35de456a02c359a1b6c4cdf280ed75d0b2ad9dde Mon Sep 17 00:00:00 2001 From: Marcus Palm Date: Wed, 10 Jan 2024 15:10:34 +0100 Subject: [PATCH] Marcus Palm csharp-fundamentals-loops --- csharp-fundamentals-loops.Main/Core.cs | 47 +++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/csharp-fundamentals-loops.Main/Core.cs b/csharp-fundamentals-loops.Main/Core.cs index 9194643..ddb02ea 100644 --- a/csharp-fundamentals-loops.Main/Core.cs +++ b/csharp-fundamentals-loops.Main/Core.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using static System.Runtime.InteropServices.JavaScript.JSType; @@ -20,32 +21,68 @@ public class Core public void stepOne() { // TODO: 1. Write a for loop that adds the numbers 0 to 3 to the numsZeroToThree array - throw new NotImplementedException(); + //throw new NotImplementedException(); + for (int i = 0; i < numsZeroToThree.Length; i++) + { + numsZeroToThree[i] = i; + } } public void stepTwo() { // TODO: 2. Write a for loop that adds the numbers 5 to 10 to the numsFiveToTen array - throw new NotImplementedException(); + //throw new NotImplementedException(); + int number = 5; + for (int i = 0;i < numsFiveToTen.Length; i++) + { + numsFiveToTen[i] = number; + number++; + } } public void stepThree() { // TODO: 3. Write a for loop that adds the numbers 3 to 0 (in that order) to the countdown array - throw new NotImplementedException(); + //throw new NotImplementedException(); + int num = 0; + for (int i = countdown.Length -1; i >= 0 ; i--) + { + countdown[i] = num; + num++; + } } public bool stepFour(int num) { // TODO: 6. Write a for loop that checks if num is in the favouriteNumbers array - throw new NotImplementedException(); + //throw new NotImplementedException(); + bool isFavouriteNumber = false; + foreach (int number in favouriteNumbers) + { + if (number == num) + { + isFavouriteNumber = true; + } + + } + return isFavouriteNumber; } public bool stepFive(string hobby) { // TODO 5. Write a for loop that checks if the hobby String is in the myHobbies array - throw new NotImplementedException(); + //throw new NotImplementedException(); + bool isInArray = false; + foreach(string Hobby in myHobbies) + { + if(Hobby == hobby) + { + isInArray = true; + } + + } + return isInArray; } }