方法必须具有值返回类型...尽管已经有一个

时间:2018-11-09 01:04:35

标签: c#

我正在尝试创建一个包含列表框标题的类。我将在列表框中插入两个类。第一个类运行良好,但是我正在制作的第二个类使数组完全由字符串组成,这告诉我方法必须具有值返回类型。这到底是什么意思?眼前的错误是“ HeaderItems”。

namespace RETAILITEMSBLAKE
{
class HeaderClass
{
    string HeaderDescription;
    string HeaderPrice;
    string HeaderUnitsonHand;

    public HeaderItems(string HeaderDescription, string HeaderUnitsonHand, string HeaderPrice)
    {
        this.HeaderDescription = HeaderDescription;
        this.HeaderUnitsonHand = HeaderUnitsonHand;
        this.HeaderPrice = HeaderPrice;
    }

    public string HeaderDescriptions
    {
        get
        {
            return HeaderDescription;
        }
        set
        {
            HeaderDescription = value;
        }
    }
    public string HeaderUnits
    {
        get
        {
            return HeaderUnitsonHand;
        }
        set
        {
            HeaderUnitsonHand = value;
        }
    }
    public string HeaderPrices
    {
        get
        {
            return HeaderPrice;
        }
        set
        {
            HeaderPrice = value;
        }
    }
}

这是我的第一堂课,工作正常:

    namespace RETAILitemsBLAKE
 {
    class ItemizedClass
   {

    string description;
    int unitsonhand;
    double price;

    public ItemizedClass(string description,int unitsonhand,double price)
    {
        this.description = description;
        this.unitsonhand = unitsonhand;
        this.price = price;

    }



    public string Description
    {
        get
        {
            return description;
        }
        set
        {
            description = value;
        }
    }
    public double Price
    {
        get
        {
            return price;
        }
        set
        {
            price = value;
        }
    }
    public int Quantity
    {
        get
        {
            return unitsonhand;
        }
        set
        {
            unitsonhand = value;
        }
    }
}
}

因此,我的目标是拥有HeaderClass,以便可以将它们作为标题放置在我的列表框中。有替代的方法吗?我想将其放在此处的代码之上:

   namespace RETAILitemsBLAKE
     {
       public partial class FrmItemList : Form
{

    ItemizedClass[] items;

    public FrmItemList()
    {
        InitializeComponent();
        ItemizedArray();
    }
    private void ItemizedArray()
    {


        ItemizedClass jackets = new ItemizedClass("Jackets", 12, 59.95);
        ItemizedClass jeans = new ItemizedClass("Jeans", 40, 34.95);
        ItemizedClass shirts = new ItemizedClass("Shirts", 20, 24.95);

        items = new ItemizedClass[] { jackets, jeans, shirts };

        foreach (ItemizedClass RetailData in items)
        {
            lstRetailitems.Items.Add(RetailData.Description + "\t\t" + RetailData.Quantity + "\t" + "$" + RetailData.Price);


        }




    }
}
  }

有人会帮忙吗?谢谢!

1 个答案:

答案 0 :(得分:1)

您使用的构造方法需要与类名相同,并且不需要设置返回数据类型,因此该方法名需要在// added the following to app.module.ts import { AppComponent } from './app.component'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { NgModule } from '@angular/core'; import { DlDateTimePickerDateModule } from 'angular-bootstrap-datetimepicker'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, FormsModule, DlDateTimePickerDateModule, ], providers: [FormsModule], bootstrap: [AppComponent] }) export class AppModule { } //added the following to app.component.html <dl-date-time-picker startView="day" maxView="year" minView="minute" minuteStep="5" [(ngModel)]="selectedDate" > </dl-date-time-picker> // added following to ./src/styles.css @import '~bootstrap/dist/css/bootstrap.min.css'; @import '~open-iconic/font/css/open-iconic-bootstrap.css';类中写入HeaderClass,否则需要将返回数据类型设置为常规方法。

HeaderClass