Answer the question
In order to leave comments, you need to log in
Removing an element in List C#?
How to update a list of elements that no longer contains an element with the specified sequence number?
public static Payment ClearPayment()
{
Console.Write("Enter code: ");
int C = int.Parse(Console.ReadLine());
var found = payments.Exists(c => c.Code == C);
if (found == true)
{
foreach (Payment n in payments)
{
payments.RemoveAt(C-1);
}
}
Answer the question
In order to leave comments, you need to log in
You can use the RemoveAll method to remove all occurrences that match the passed predicate:
public static void ClearPayment()
{
Console.Write("Введите код: ");
int C = int.Parse(Console.ReadLine());
if (payments.RemoveAll(p => p.Code == C) > 0)
Console.WriteLine("Указанный платеж удален ");
else
Console.WriteLine("Платежа с таким кодом не существует");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question