Performance is not a problem in my project, I want to know a simpler and readable replacement for my foreach using Linq and Lambda (if possible).
// 'DiscoVirtual' é uma classe
// 'this.HDs' é um 'List<DiscoVirtual>'
// 'Atual' e 'Novo' são instâncias de 'DiscoVirtual'
foreach (DiscoVirtual d in this.HDs)
{
if (d == Atual)
{
this.HDs.Remove(Atual);
if (Novo != null) this.HDs.Add(Novo);
}
}
In addition to this, if Novo
is null
I only want it to remove Atual
(I've completed the code).