If I have a string of digits and int
variables a, b, c
and I want to assign the first digit to int a
, the second to int b
and so on, how do I do that? This snippet illustrates my problem:
var str = "123";
int a = Convert.ToInt32(str[0]);
Console.WriteLine(str[0] + " " + a );
Output:
1 49
What do I do (besides subtract 48 from every attempted conversion)?
EDIT
Today I learned that str[0]
produces a Char
, not a string
.