+ 1

Working with Strings C#

Hi, i tryed to work with strings for challenges, but i came to a problem. Whenever i tried to use any part of an numeral string as an int (via Convert.ToInt32(string[part]) ) it ended up with 49, 50 and so on, but never with the number it was on the string. You can see it in my Code "Magic Square" (https://code.sololearn.com/cADgEdj4zBm8/#cs) for the Challenge with the same name. Can someone help me fixing it, or better explain my mistake?

22nd Aug 2018, 6:30 PM
Karl G.
Karl G. - avatar
2 odpowiedzi
+ 1
instead of Convert.ToInt32(string[part]) use int.Parse(string[part].ToString()) because the Convert method with a character returns an ascii code
22nd Aug 2018, 8:03 PM
hinanawi
hinanawi - avatar
0
thanks a lot
23rd Aug 2018, 2:34 AM
Karl G.
Karl G. - avatar