If you want to initialize the array from the two other arrays and the int, you could use:
private bool ArrayMaking(int[] array1, int[] array2, int value, out int[] arrays)
{
int size = array1.Length + array2.Length + 1;
arrays = new int[size];
for (int i = 0; i < array1.Length; i++)
arrays[i] = array1[i];
for (int i = 0; i < array2.Length; i++)
arrays[i + array1.Length] = array2[i];
arrays[arrays.Length - 1] = value;
return true;
}
less efficient but more readable using LINQ:
private bool ArrayMaking(int[] array1, int[] array2, int value, out int[] arrays)
{
arrays = array1.Concat(array2).Concat(new[] {value}).ToArray();
return true;
}
boolis not relevant for the array filling process, the method can be void, too. In my Method I check, if the values inarray1andarray2are okay. If yes, I return the solution shown, if not, I try to change the values of array2 and after the adaption I fill thearrayswith{array1, array2, value}. If the adaption is not possible, I return false. The code posted throws an error in Visual Studio, saying "Invalid Expression "{""