2021年4月8日星期四

Assigning an integer to a char array c#

I tried inserting integers into a char array and failed, for some reason when I assign a value (for example charc[0] = 2) I get this weird value of '50', and when I tried debugging I noticed there are actually 2 values for each cell in the array, for example when I assigned charc[0] = 2 it showed me 2 different values: "50,'2'"). Therefore I when I try and access the value in each cell I get the 50 (Which I read is the ASCII value) instead of the desirable 2. The "line" variable contains a string in this format: "23x11x5" (3 seperate nubmers with a "x" between them). This is the code:

 StreamReader sr = new StreamReader("TextFilePathHere.txt");             line = sr.ReadLine();             char[] charc = new char[line.Length];                  charc = line.ToCharArray();  
https://stackoverflow.com/questions/67010221/assigning-an-integer-to-a-char-array-c-sharp April 09, 2021 at 02:55AM

没有评论:

发表评论