c# - Application breaks with System.FormatException(not correct input type?) -
im making treegenerator training , im taking input console splitting array while trying split error saying system.formatexception(not correct input type)
console.writeline("input number of branches, treefoot, , branch char"); string[] input = console.readline().split(' '); int nb = int.parse(input[1]); char tf = char.parse(input[2]); char bc = char.parse(input[3]);
your index 0 not int in string, text in string.
you got indices wrong, use 0,1,2
int nb; bool ok = int.tryparse(input[0], out nb); // ok true if parsing succeeded char tf = char.parse(input[1]); char bc = char.parse(input[2]); you should use int.tryparse() see if int parsing succeeded.
Comments
Post a Comment