diff --git a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Model.cs b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Model.cs index 73acea3..3cf5456 100644 --- a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Model.cs +++ b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Model.cs @@ -43,12 +43,22 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes // Get KeyValuePair by id, returns [-1, "Invalid Record"] when out of bounds public KeyValuePair find(int id = 1) { - KeyValuePair record = new KeyValuePair(-1, "Invalid Record"); - if (this.table_data.ContainsKey(id)) + // Initialize KeyValuePair as null + KeyValuePair record; + // Populate using record from dictionary + record = new KeyValuePair(id, this.table_data.GetValueOrDefault(id)); + // Handle default value + if(record.Value == default) { - record = new KeyValuePair(id, this.table_data.GetValueOrDefault(id)); + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"Attempting to request invalid record with id: {id}"); + Console.ResetColor(); } - this.record = record; + else + { + this.record = record; + } + // Return record return record; } }