+ 1
Why method with array return incremented value?
5 Answers
+ 4
I agree with sneeze
That's why after calling the AddOne functions from main function value change in AddOne function effect on entire code..
+ 3
An array is a reference type, so it does not need the ref keyword.
Think of it as passing the address of some variables
The address is not changed
Using the address you can change the value of the variables
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/passing-arrays-as-arguments
+ 2
a[0]=7;
AddOne(a)
After call AddOne() a[0] increase because when you pass a array element to that function it's increase first index value as
x[0] +=1;
That's why 7 increase to 8..
+ 1
But i don't use linking !? If I want that value will be incremented in method without return, or out - it's must be 'ref' value
+ 1
Thank you!