private void buttonSend_Click(object sender, EventArgs e) { try { string tip = tbTip.Text; string model = tbModel.Text; int nrOptiuni = Convert.ToInt32(tbNrOptiuni.Text); float pret = (float)Convert.ToDouble(tbPret.Text); string[] sPretOptiuni = tbPretOptiuni.Text.Split(','); float[] pretOptiuni = new float[sPretOptiuni.Length]; for (int i = 0; i < sPretOptiuni.Length; i++) { pretOptiuni[i] = (float)Convert.ToDouble(sPretOptiuni[i]); } Suv s = new Suv(model, nrOptiuni, pretOptiuni, pret, tip); MessageBox.Show(s.ToString()); listaSuv.Add(s); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { tbModel.Clear(); tbNrOptiuni.Text = ""; tbPret.Text = ""; tbPretOptiuni.Text = ""; tbTip.Text = ""; } }
public object Clone() { Suv nou = (Suv)this.MemberwiseClone(); nou.numarOptiuni = this.numarOptiuni; nou.pretOptiuni = (float[])pretOptiuni.Clone(); return(nou); }
public int CompareTo(object obj) { Suv suv = (Suv)obj; if (suv.calculPretOptiuni() > this.calculPretOptiuni()) { return(1); } else { if (suv.calculPretOptiuni() < this.calculPretOptiuni()) { return(-1); } else { return(string.Compare(this.model, suv.model)); } } }