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);} }
4 Answers
+ 2
Andrey
a[2] = 7
When you convert "7" to integer then you get ASCII value which is 55
+ 2
Andrey
1 - as a[2] gives "7" which is consider as a character so to get 7 as an integer you have to make it string then convert to int like this:
int y= Convert.ToInt32(a[2] + "");
//this will give 7
2 - Use Int16.Parse method
int y = Int16.Parse(a[2] + "");
a[2] is a character so I make it String because this method except string.
+ 1
ooh ok, Thank you very much AJ.
0
And what should I do to make it 7?