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
HDs
has Setter or just getter?– dcastro
To clarify, the intention of the code is to replace the disk
Actual
forNovo
? And if the list doesn’t containActual
, nothing happens?– dcastro
Both:
{ get; private set; }
. This section is within the class.– Marcelo Nascimento
Atual
is already on the listthis.HDs
. Can’t not be. I want to change the reference ofAtual
by reference toNovo
– Marcelo Nascimento