Как исправить argumentoutofrangeexception ?
Hi, I Have 10 PhoneNumbers, it take numbers from TextBox. if im add 10 Numbers to listbox it Works fine. But less than 10 Numbers it wont Works, it thrown Exceptions. (For Ex : Now im add only 2 numbers to listbox and click on submit button it shows a exception for Number3 in Code.) Exception : An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in PresentationFramework.dll Additional information: Specified argument was out of the range of valid values.
Что я уже пробовал:
private SOTA_whitelist_Number RetrieveSOTAConfiguration() { string Number1; string Number2; string Number3; string Number4; string Number5; string Number6; string Number7; string Number8; string Number9; string Number10; Number1 = ListBox_PhoneNumber.Items[0].ToString(); Number2 = ListBox_PhoneNumber.Items[1].ToString(); Number3 = ListBox_PhoneNumber.Items[2].ToString(); Number4 = ListBox_PhoneNumber.Items[3].ToString(); Number5 = ListBox_PhoneNumber.Items[4].ToString(); Number6 = ListBox_PhoneNumber.Items[5].ToString(); Number7 = ListBox_PhoneNumber.Items[6].ToString(); Number8 = ListBox_PhoneNumber.Items[7].ToString(); Number9 = ListBox_PhoneNumber.Items[8].ToString(); Number10 = ListBox_PhoneNumber.Items[9].ToString(); Console.WriteLine("\n Print Number1 and Number2 {0}, {1}", Number1, Number2); return new SOTA_whitelist_Number(Number1, Number2, Number3, Number4, Number5, Number6, Number7, Number8, Number9, Number10); }
[ОБНОВЛЕНИЕ] :
Я пробовал с циклом For, но он не работает, будет выброшено такое же исключение.
string[] Number = new string[20]; for (i = 1; i <= ListBox1.Items.Count; i++) { Number[i] = ListBox1.Items[i].ToString(); }