Created
July 15, 2020 12:52
-
-
Save Sheepings/22b35f79ab3a3bba5c8c319dc765cfc8 to your computer and use it in GitHub Desktop.
A snipped for removing items from an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Student | |
{ | |
public string Name { get; set; } | |
public enum Gender | |
{ | |
Male, Female | |
} | |
public int Age { get; set; } | |
public string[] Grades { get; set; } | |
public string[] Subjects { get; set; } | |
} | |
public static class Student_Grading | |
{ | |
public static Student Graded_Student(Student with_Student, string[] with_Studied_Subjects, string[] with_Grades) | |
{ | |
if (with_Studied_Subjects.Length == with_Grades.Length) | |
{ | |
with_Student.Grades = with_Grades; | |
with_Student.Subjects = with_Studied_Subjects; | |
return with_Student; | |
} | |
else | |
{ | |
throw new ArgumentOutOfRangeException("Subjects taken do not contain an equal amount of grades."); | |
} | |
} | |
public enum Grades | |
{ | |
A, B, C, D, E, F | |
} | |
public enum Subjects | |
{ | |
Geography, Maths, English, Art, Science | |
} | |
} | |
public static class Helper | |
{ | |
public static Student Remove_FromArray(Student thisStudent, string[] removeSubjects) | |
{ | |
List<string> list_OfType = new List<string>(); | |
if (thisStudent.Subjects.Length > removeSubjects.Length) | |
{ | |
removeSubjects.ToList().ForEach((string unwanted_Subject) => | |
{ | |
foreach (string value in thisStudent.Subjects) | |
{ | |
if (unwanted_Subject != value && !list_OfType.Contains(value)) | |
list_OfType.Add(value); | |
} | |
}); | |
thisStudent.Subjects = list_OfType.ToArray(); | |
} | |
else | |
{ | |
throw new ArgumentException("You're trying to remove more items than your collection of items contains."); | |
} | |
return thisStudent; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment