I want to take two string input from user in c#, and than convert them to integer by their position in array and then add them. My code is the one below.
string a = Console.ReadLine();
string b = Console.ReadLine();
c = Convert.ToInt32(a[i]);
d = Convert.ToInt32(b[i]);
j = c + d;
When you use the string (array) like a[i] you are not getting what you want...
The way you are referencing the string is the problem. Even though “a” is a string... when you reference it like
c = Convert.ToInt32(a[i]); a[i] is going to return something else. You want to get a[i]’s value.
c = Convert.ToInt32(a[i].ToString()); d = Convert.ToInt32(b[i].ToString());