Why is my method changing the original value | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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