c# - Reading in values into Array -


this program asks user array size asks user enter in array values. problem having loop read in array values doesn't work properly. no matter value nit sitll ask lot more inputs.

int n;  console.writeline("enter how many values entering in"); n = convert.toint32(console.read());  int[] arr = new int[n]; console.writeline("enter values in");  (int = 0; < n; i++) {     arr[i] = convert.toint32(console.read()); } 

quick , easy fix:

use int.parse(console.readline()) in place of convert.toint32(console.read())

explanation:

you getting ascii value way doing it. example, if type in number 2 n variable have been set 50.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -