I'm trying to figure out how this piece of code is executed step by step to better understand it. You type a word into the console and it spits out the word in reverse.
I can follow the code until I get to array[name.Length - i] = name[i - 1];
var array = new char[name.Length];
for (var i = name.Length; i > 0; i--)
array[name.Length - i] = name[i - 1]; <------
I don't get how the steps of this one line of code is translated. Why do we subtract 1 from name.Length then subtract it by itself represented by i
? What does subtracting 1 from i
in name[i - 1]
accomplish?