why is the output of "y" 55? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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);} }

24th Jun 2022, 3:32 AM
Andrey
3 Answers
+ 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.
24th Jun 2022, 4:07 AM
Ipang
+ 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.
24th Jun 2022, 5:46 AM
Andrey
+ 1
No problem Andrey Administrator of the page? I think you misunderstood me for someone else. It's ok though 👌
24th Jun 2022, 5:49 AM
Ipang