Sunday, 15 April 2012

c# - user input initialized array example and implicit conversion -


Is there a way to remove an unwanted exception line so that "input string" will be "correct" in the "format"? I do not remember working for this kind of incompatible underlying conversion ... exception exception on the statement for the first loop.

  Public category ArrayTest {public static void Main () {// array int [] start myArray; Console.light line ("Enter the size of an array"); Int array = Convertible = Convert toInt32 (console .readlines ()); MyArray = new int [array]; Console.light line ("element on index {{}", flexible variable); Console.light line ("enter elements of array"); (Int i = 0; i & lt; array variable; i ++) {myArray [i] = convert to. ToInt32 (console .readline ()); } (Int i = 0; i & lt; random, i ++) // display array elements {console. Element ("{0} {1} element:", i, myArray [i]); }}}  

TryParse Inut's type

  public class ArrayTest {public static zero main () {// array int [] begin myArray; Console.light line ("Enter the size of an array"); Int array = Convertible = Convert toInt32 (console .readlines ()); MyArray = new int [array]; Console.light line ("element on index {{}", flexible variable); Console.light line ("enter elements of array"); For (Int i = 0; I & lt; array variable; I ++) {string input = Console.ReadLine (); Full result; If (int.TryParse (input, results out)) {myArray [i] = results; } And (i--; console (for "invalid input format");}} (int i = 0; i & lt; sanctification; i ++) // display array elements {console.promised (" Elements on {0} {1}: ", i, myArray [i]);}}}  


No comments:

Post a Comment