填充节目的对象数组

时间:2013-11-25 00:45:48

标签: c# arrays object

为什么这不起作用。以下是我的代码:

private static void FillCatalogue()
         {
         int intCatalogueNumber = 0;
         arrMyShows = new Show[intCatalogueNumber];

         Show newShow = new Show();
         //arrMyShows[intCatalogueNumber] = newShow;
         Console.Clear();
         Console.Write("Title: ");
         arrMyShows[intCatalogueNumber].Title = Console.ReadLine();
         Console.Write("Year: ");
         arrMyShows[intCatalogueNumber].Year = Convert.ToInt32(Console.ReadLine());
         Console.Write("Lead Actor: ");
         arrMyShows[intCatalogueNumber].LeadActor = Console.ReadLine();
         Console.Write("Price: ");
         arrMyShows[intCatalogueNumber].RentalPrice =        Convert.ToDouble(Console.ReadLine());
         //Console.Write("Does the show have Blu-Ray discs?  (Y/N) ");

         Console.WriteLine(arrMyShows[intCatalogueNumber].Title + " " + arrMyShows[intCatalogueNumber].Year + " " + arrMyShows[intCatalogueNumber].LeadActor);

1 个答案:

答案 0 :(得分:2)

您的数组arrMyShows的大小为0;当然这不会起作用。给它另一个值:

int intCatalogueNumber = 0;
int size = SOMETHING;
arrMyShows = new Show[size];