In PHP , I can create a new array
based on an existing array
, using the array_map
function.
With it, I can define a callback that is responsible for the settings of each value that will be used to create this "new array
".
Example in PHP:
$numeros = [1, 2, 3];
$numeros_dobrados = array_map(function ($value)
{
return $value * 2;
}, $numeros);
print_r($numeros); // [2, 4, 6]
I also know you can do this in python
.
Example in Python:
[x * 2 for x in range(1, 10) ]
> [2, 4, 6, 8, 10, 12, 14, 16, 18]
How could I do this with this array in C #?
C # example:
var arr = new int[] {1, 2, 3}