I'm getting below exception while trying to print the last element in an array.
here is my code:
int[] nums = { 1, 2, 5, 7, 8 };
Console.WriteLine("first element is " + nums[0]);
int fe = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Last element is {0}" , nums[nums.Length - 1]);
int le = Convert.ToInt32(Console.ReadLine());
Exception:
first element is 1
Unhandled Exception: System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Convert.ToInt32(String value) at W2Resource.BasicExProb51.Main() in C:\Users\SudhaPraveen\Documents\Visual Studio 2017\Projects\CSharpPractice21DaysPlan\W2Resource\BasicExProb51.cs:line 16 Press any key to continue . . .