0
replace the value of each element of an integer array with the sum of this element value and its index
How to replace the value of each element of an integer array with the sum of this element value and its index in C#
6 Respuestas
+ 2
Write each element of the returned array using `foreach`
foreach( int element in Transform( numbers ) )
{
Console.WriteLine( element );
}
+ 2
Try to change return type into `int[]` rather than `object`.
+ 1
What is "this" element?
+ 1
using System;
namespace ConsoleApp3
{
class Program
{
public static int[] Transform(int[] numbers)
{
for (int i = 0; i < numbers.Length; i++)
{
numbers[i] = numbers[i] + i;
}
return numbers;
}
public static void Main(string[] args)
{
int[] numbers = { 1, 21, 3, 25 };
Console.WriteLine(Transform(numbers));
}
}
}
Thanks! But it's still nothing in the console :-(
+ 1
Wow!
It worked!
Thank you a lot!
0
in other words - increase each array element by its index
I try something like this, but it's not working:
public static object Transform(int[] numbers)
{
for (int i = 0; i < numbers.Length; i++)
{
numbers[i] = numbers[i] + i;
}
return numbers;