Resolved issue described in https://github.com/MeesterReneOrg/oop-csharp-Hion-V/issues/1#issue-1524609342
This commit is contained in:
parent
e6cc7d48e2
commit
28ef9a8c4f
@ -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<int, string> find(int id = 1)
|
||||
{
|
||||
KeyValuePair<int, string> record = new KeyValuePair<int, string>(-1, "Invalid Record");
|
||||
if (this.table_data.ContainsKey(id))
|
||||
// Initialize KeyValuePair as null
|
||||
KeyValuePair<int, string> record;
|
||||
// Populate using record from dictionary
|
||||
record = new KeyValuePair<int, string>(id, this.table_data.GetValueOrDefault(id));
|
||||
// Handle default value
|
||||
if(record.Value == default)
|
||||
{
|
||||
record = new KeyValuePair<int, string>(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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user