0
why is the output of "y" 55?
static void Main(string[] args) { string[] num = new string[3]{"54230","677809","90132"}; for(int i=0;i<3;i++){ string a = num[1]; int y= Convert.ToInt32(a[2]); Console.WriteLine(a[2]); Console.WriteLine(y);} }
3 Respostas
+ 1
I saw you posted this yesterday, if you want <y> to have value of 7, then you need to subtract the ASCII value of character a[ 2 ] by ASCII value of character zero ('0'), as follows
int y = Convert.ToInt32( a[ 2 ] - '0' ); // notice single quote -> character, not string
ASCII value of '7' was 55, and ASCII value of '0' was 48. Subtraction of the two will result in 7, the value you desire.
+ 1
Thank you very much Ipang, I do not know if you are an administrator of the page because you are almost always the one who gives me the solutions, but I thank you very much. Pura vida.
+ 1
No problem Andrey
Administrator of the page? I think you misunderstood me for someone else. It's ok though 👌