2021年1月15日星期五

Reverse Sting, Array

I couldn't understand this part arr[name.Length - i] = name[i - 1];

Let us have a name of 5 characters. so the value of the arr will be 4, right?

then in the loop, the looping variable is also taking the same length, so its initial value will be 4 too.

in the first iteration, the value of arr[4 - 4] will be arr[0] and name[4 - 1] will be name[3] so the first index of arr is copied with the fourth index of name.

How the hell is then the original name was stored in reversed order in arr?

C# code for reversing a string

https://stackoverflow.com/questions/65746100/reverse-sting-array January 16, 2021 at 11:06AM

没有评论:

发表评论