如何进行抽象覆盖以将结果显示在Windows窗体的标签中?

问题描述

这是我尝试过的:

 public abstract double getTotalPrice();

 public override double getTotalPrice()
    {

        this.discounted_price = (item_price * item_quantity) - (item_price * item_quantity * item_discount / 100);
        return discounted_price;
        
    }

我试图将其放在这样的标签中:

 private void button1_Click(object sender,EventArgs e)
    {
        discountedItem di = new discountedItem(textBox1.Text,Convert.Todouble(textBox2.Text),Convert.ToInt32(textBox3.Text),Convert.Todouble(textBox4.Text));

        
        label10.Show(di.getTotalPrice().ToString());


    }

当我单击按钮时,它将计算总价格,然后将其显示标签中。 我一直在搜索,但是找不到确切的解决方案。

解决方法

使用

label10.Text = di.getTotalPrice().ToString();

代替Show()