3
Performance is not an issue 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);
}
}
Beyond the but, if Novo for null I just want it removed Atual (I supplemented the code).
The estate
HDshas Setter or just getter?– dcastro
To clarify, the intention of the code is to replace the disk
ActualforNovo? And if the list doesn’t containActual, nothing happens?– dcastro
Both:
{ get; private set; }. This section is within the class.– Marcelo Nascimento
Atualis already on the listthis.HDs. Can’t not be. I want to change the reference ofAtualby reference toNovo– Marcelo Nascimento