try { int a = Convert.ToInt32(txt1.Text); lbInt.Items.Add(a.ToString()); } catch (Exception) { lbString.Items.Add(txt1.Text); }