-2

example I enter 1357 and program out 106 instead of 10

        string num = Console.ReadLine();
        Console.Write(Convert.ToInt32(num[1]) + Convert.ToInt32(num[3]));
        Console.ReadKey();
newdw
  • 23
  • 3

1 Answers1

2

First convert the single characters to a string before converting to integer. Convert will use the Unicode code point value when converting char to integer directly.

var value = Convert.ToInt32(num[1].ToString()) + Convert.ToInt32(num[3].ToString());
NineBerry
  • 26,306
  • 3
  • 62
  • 93