2012-08-02 51 views
0

我已經遇到了一些問題,雖然我在這個小項目中工作檢查信息是否在Equal方法中輸入之前?

它說我必須實現稱爲Equal的方法,以便Product對象可以顯示並檢查它們是否相等。演示如何使用產品對象構建產品對象,輸入或編輯產品標識,名稱和值,然後使用字符串顯示標識,名稱和值。

我到目前爲止所做的一切,有等問題的方法

namespace Question_two2 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     public class Prouduct 
     { 
      // properities 
      public int id; 
      public string nameOfproduct; 
      public double value; 

      // constructor 
      public Prouduct() 
      { 
       id = 0; 
       nameOfproduct = ""; 
       value = 0.0; 
      } 
      // ToString method to diplay all the information about the Prouduct 
      public void ToString(int id_ , string nameOfproduct_ , double value_) 
      { 

       id = id_; 
       nameOfproduct = nameOfproduct_; 
       value = value_; 

      } 
      public void Equal() 
      { 
       Prouduct prod = new Prouduct(); 

       prod.ToString(); 
      } 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      // create new object 
      Prouduct pro = new Prouduct(); 
      // take all the information from textBoxs 
      int id1 = int.Parse(textBox1.Text); 
      string nameOfproduct1 = textBox2.Text; 
      double value1 = double.Parse(textBox3.Text); 

      // to use the toString method 
      pro.ToString(id1, nameOfproduct1, value1); 

      // to diplay all the information about product in the listBox 

      listBox1.Items.Add("s"+pro.id + "  " + pro.nameOfproduct + "  " + pro.value); 

     } 
    } 
} 
+1

我強烈懷疑你是否真的打算覆蓋現有的'Equals(object)'方法而不是創建一個新的無參數'Equal'方法。 – 2012-08-02 06:38:35

回答

相關問題