With this line:
char[] inputnew = input;
you copy the reference of array input
to the reference of inputnew. This is how object oriented programing work. You always have reference of objects. That's why the types are also called Reference Type. On the other side you have Value types which actually copy the value, like int
and boolean
.
If you want to copy the actual values of your Array, you have to use the function Array.Copy(sourceArray, TargetArray)
like this:
char[] input = { 'h', 'e', 'l', 'l', 'o' };
char[] inputnew;
Array.Copy(input, inputNew);
Array.Reverse(inputnew);
Console.WriteLine(new string(input));
Console.WriteLine(new string(inputnew));