1
Answer

assigning new array to the array passed by reference

Photo of Jon Smit

Jon Smit

6y
452
1
write a OddNumbers method,The method should take an integer array passed using the ref keyword.
After the method is executed the array that was passed in should retain contain only the even numbers in the same order, and should have no space free
 
using System;

namespace HelloWorld
{
class Program
{
static string GetArrayAsString(int[] array)
{
if(array.Length == 0) return "";

string str = "";
int i = 0;
for(; i < array.Length - 1; i++)
{
str += array[i] + ", ";
}
str += array[i];

return str;
}


static void Main(string[] args)
{
int[] array = { 3, 8, 12, 31, 5, 78, 90 };
removeOddNumbers(ref array);

Console.WriteLine(GetArrayAsString(array));
}
}

Answers (1)