I'm new to C# and writing a text moving cipher program. However, when trying to set an array value to a value from another array (plus 3) i always get an IndexOutOfRangeException. That might sound confusing but honestly I have no clue how to really word this.
Removing the +3 didn't help, and it seems trying to set the array from another array always results in the error.
for (int i = 0; i < CipherLength; i++)
{
if (Alphabet.Contains(CipherArray[i]))
{
Console.WriteLine(i);
Console.WriteLine(CipherArray[i]);
CipherArray[i] = Alphabet[CipherArray[i + 3]];
}
else
{
CipherArray[i] = ' ';
}
}
Essentially, i'm trying to set the CipherArray value, in this case the character, to be that character moved by 3, which is what the alphabet array is for.
Expected: If CipherArray[i] = A
, then after that it should equal D
Actual:
System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
(In all cases)