+ 1

Why method with array return incremented value?

https://code.sololearn.com/coNxJU36PwdF/?ref=app

26th Mar 2019, 4:46 PM
id001x
id001x - avatar
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..
27th Mar 2019, 1:59 AM
Scooby
Scooby - avatar
+ 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
26th Mar 2019, 9:52 PM
sneeze
sneeze - avatar
+ 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..
26th Mar 2019, 5:19 PM
Scooby
Scooby - avatar
+ 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
26th Mar 2019, 5:24 PM
id001x
id001x - avatar
+ 1
Thank you!
27th Mar 2019, 1:57 AM
id001x
id001x - avatar