private void listBox3_SelectedIndexChanged(object sender, EventArgs e) { if (!int.TryParse(listBox3.GetItemText(listBox3.SelectedItem), out int id)) { Console.WriteLine("{0} is not an integer", id); } else { id = Convert.ToInt32(listBox3.GetItemText(listBox3.SelectedItem)); } Train.AnimalInfo(listBox3, AnimalID, AnimalSize, AnimalMeatEater, id); }