检查是否在Equal方法之前输入了信息?

时间:2012-08-02 06:32:52

标签: c# class object methods

我在这个小项目中工作时遇到了一些问题

它说我必须实现名为Equal的方法,以便Product对象可以显示并检查它们是否相等。演示如何使用您的产品对象,输入或编辑产品ID,anme和值,然后使用字符串显示Id,名称和值

到目前为止我所做的一切我已经完成了所有事情,但仍然存在Equal方法的一些问题

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);

        }
    }
}

0 个答案:

没有答案