Hi I have some background in Javascript, and I used .filter()
and .map()
a lot, recently I have a c# project, I am new to c# just wondering is there a C# function which is similar to .Map()
in JavaScript? I know that .where()
is very similar to .filter()
.
btw .map()
is like
const newArray = array1.map(
el => {
if(el.id===1){
el.name='foo';
return el;
}
return el;});
and it returns a new array. .FroEach()
does not return a new array.
My account got blocked by some down votes questions, the funny thing is I have to re-edit them, even though I already have the accepted answer.I do not understand what's the point to do this.I am so frustrated by this stackoverflow system.
Now, I basically can do nothing but keep editing my questions, and they have all been answered. This is ridiculous !!!
You can Use .Select()
:
array.Select(el =>
{
if(el.id == 1)
{
el.name="foo";
return el;
}
return el;
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With