+ 1

Why is my method changing the original value

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

22nd Jul 2021, 6:26 PM
CodeSmith
CodeSmith - avatar
2 odpowiedzi
+ 6
~LoneWolf Because reference is same. You have passed str as a parameter and assigned to tempArr so reference of str and tempArr is same. Solution is clone the original array then assign to tempArr like this: string[] tempArr = (string[]) arr.Clone(); https://code.sololearn.com/c2oGVT26RGH6/?ref=app
22nd Jul 2021, 6:29 PM
A͢J
A͢J - avatar
+ 2
A͢J thanks for the solution😀👍
22nd Jul 2021, 6:36 PM
CodeSmith
CodeSmith - avatar