只有列表中的最后一项显示在数据模板中



我有 5 个内容,我想在应用程序启动时显示在 wrapT面板中,但不幸的是,它没有按我想要的方式工作。当我运行应用程序时。

public class Company
{
    public String EventName { get; set; }
    public String Attendees { get; set; }
    public String Date { get; set; }
}

}

我希望所有内容都显示出来,但只有远足节目

您遇到此问题的原因是因为您正在用每个新值覆盖名为"com"的变量。

com = new Company { EventName = "Code Talks" ,Attendees ="50" , Date = "25/oct./2019" };
com = new Company { EventName = "Tic Tac", Attendees = "70", Date = "55/oct./2019" };
com = new Company { EventName = "Loney Talks", Attendees = "30", Date = "5/oct./2019" };
com = new Company { EventName = "Cofee Talks", Attendees = "50", Date = "25/oct./2019" };
com = new Company { EventName = "Hiking ", Attendees = "40", Date = "75/oct./2019" }; 

这相当于尝试存储几个整数,如下所示:

x=5;
x=4;
x=1;

您将需要使用某种数组并将每个项目添加到其中。如果您只打算使用这 5 个项目,那么固定长度的数组将正常工作:

Company[] coms = new Company[5];
coms[0] = new Company { EventName = "Code Talks" ,Attendees ="50" , Date = "25/oct./2019" };
coms[1] = new Company { EventName = "Tic Tac", Attendees = "70", Date = "55/oct./2019" };
coms[2] = new Company { EventName = "Loney Talks", Attendees = "30", Date = "5/oct./2019" };
coms[3] = new Company { EventName = "Cofee Talks", Attendees = "50", Date = "25/oct./2019" };
coms[4] = new Company { EventName = "Hiking ", Attendees = "40", Date = "75/oct./2019" }; 

相关内容

  • 没有找到相关文章

最新更新