public static void PromptDeletion<T>(ref T[] values, Func<T, string> repr)
{
List<T> tempValues = new(values);
ShowValuesInOrder([.. tempValues], repr);
Console.WriteLine("Values to delete> ");
string input = Console.ReadLine() ?? "";
string[] deletions = input.Split(',');
// Tries to delete the objects at the specified indices, but each iteration removes objects from the array BEFORE the NEXT iteration/deletion
try
{
foreach (string value in deletions)
{
if (value.Count(s => s == '-') == 1)
{
int[] ends = value.Split('-').Select(n => Convert.ToInt32(n) - 1).ToArray();
tempValues.RemoveRange(ends[0], ends[1] - ends[0]);
}
else
{
tempValues.RemoveAt(Convert.ToInt32(value));
}
}
values = [.. tempValues];
}
catch (Exception)
{
ConsoleExt.WriteError("There was a problem removing the values.");
}
}
public static void PromptDeletion<T>(ref T[] values, Func<T, string> repr)
{
List<T> tempValues = new(values);
ShowValuesInOrder([.. tempValues], repr);
Console.WriteLine("Values to delete> ");
string input = Console.ReadLine() ?? "";
string[] deletions = input.Split(',');
// Tries to delete the objects at the specified indices, but each iteration removes objects from the array BEFORE the NEXT iteration/deletion
try
{
foreach (string value in deletions)
{
if (value.Count(s => s == '-') == 1)
{
int[] ends = value.Split('-').Select(n => Convert.ToInt32(n) - 1).ToArray();
tempValues.RemoveRange(ends[0], ends[1] - ends[0]);
}
else
{
tempValues.RemoveAt(Convert.ToInt32(value));
}
}
values = [.. tempValues];
}
catch (Exception)
{
ConsoleExt.WriteError("There was a problem removing the values.");
}
}