So you already got a
string
from
Console.ReadLine()
. So why go through that crazy conversion from a string to an
int
, and then back to a string again?
Also, unless you are planning on changing the characters of a string, there is no need to make the string into an char array. This should cover what you need:
Console.WriteLine("Enter number = ");
string input = Console.ReadLine();
if (!int.TryParse(input, out int value))
Console.Error.WriteLine($"{input} is not a number.");
for(int i = 0; i < input.Length; i++)
{
char ch = input[i];
Console.WriteLine($"input[{i}] is '{ch}'");
}
I'm still not seeing why you would need negative indexes.
As a quick aside, if you know that the input is an integer, you could just divide by 10 and get the remainder using the modulo operator to get the last digit.