First of I need to be clear on the fact that I'm new to C#. I believe in a practical approach so I've mixed my reading with practical examples. I also enjoy reading code and trying to really understand it. However this one thing keeps me puzzled.
I've checked my books and the internet but I don't really know what to search for in order to find it.
Anyway here's the code.
for (int t = 0; t < res.Length / 2; t++)
{
if (res[t] != res[res.Length -t -1]) Initial = false;
}
res isn't declared as an array earlier in the code, yet it's made res[t] in the if statement. I read something about "indexing" elsewhere but didn't get much further so now I'm asking you for help explaining this little trick for me. Hopefully the explanation wont blow my mind to pieces.
Thanks in advance.
resdeclared as? That would help us explain as there are many data structures in C# that can be iterated through that aren't declared as arraysres? You can index with [] on arrays, strings, and every type defining an indexer withthis[...]Initial(some kind of indicator, if the string is a palindrome?) is set to false. - A string is basically an array of characters (char[]) so every character can be accessed by it's position in the string, starting with zero.