0

I am trying to create a simple object-oriented program for a fictional movie theatre. Therefore I am making a kind of list with all the movies. My issue is that I can not add genres to my genre array in the child classes to the Movies class.

Here is what I have made so far.

using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BentesBio
{
    class Program
    {
        static void Main(string[] args)
        {
            Movie[] moviesArray = new Movie[6];

            moviesArray[0] = new FeatureFilm { Director = "", Country = "", Budget = 0.0, BudgetCurrency = "", BudgetDKK = 0.0, Year = 0000, Score = "", Length = 00, Genre = { "", "" }, Cast = {} };
            moviesArray[1] = new FeatureFilm { Director = "", Country = "", Budget = 0.0, BudgetCurrency = "", BudgetDKK = 0.0, Year = 0000, Score = "", Length = 00 };
            moviesArray[2] = new FeatureFilm { Director = "", Country = "", Budget = 0.0, BudgetCurrency = "", BudgetDKK = 0.0, Year = 0000, Score = "", Length = 00 };
            moviesArray[3] = new FeatureFilm { Director = "", Country = "", Budget = 0.0, BudgetCurrency = "", BudgetDKK = 0.0, Year = 0000, Score = "", Length = 00 };
            moviesArray[4] = new Documentary { Director = "", Country = "", Budget = 0.0, BudgetCurrency = "", BudgetDKK = 0.0, Year = 0000, Score = "", Length = 00, Theme = { "", "" } };
            moviesArray[5] = new Documentary { Director = "", Country = "", Budget = 0.0, BudgetCurrency = "", BudgetDKK = 0.0, Year = 0000, Score = "", Length = 00 };


            Console.ReadKey();
        }
    }

    class Movie
    {
        public string Director { get; set; }
        public string Country { get; set; }
        public double Budget { get; set; }
        public string BudgetCurrency { get; set; }
        public double BudgetDKK { get; set; }
        public int Year { get; set; }
        public string Score { get; set; }
        public int Length { get; set; }
    }

    class FeatureFilm : Movie
    {
        public string[] Genre { get; set; }
        public string[] Cast { get; set; }
    }

    class Documentary : Movie
    {
        public string[] Theme { get; set; }
    }
}

Any suggestions would be much appreciated.

1
  • 1
    Use List<T> instead arrays (T[]) ... arrays are hard to expand (you need to create bigger and copy elements from old one) Commented Feb 20, 2020 at 10:15

3 Answers 3

1

In programming languages, arrays normally are fixed size. If you don't like the size, you have to create a new one with a different size. If you want a container with a variable size, where you can add and remove elements at will, this is commonly called a list.

In C# for your purpose, that would be a List<string> instead of a string[].

Sign up to request clarification or add additional context in comments.

Comments

1

Replace -

Genre = { "", "" }

with -

Genre = new string[] { "", "" }

And same goes for assignment of Theme

And yes as per other answers you should use List<T> that'll give you flexibility to add random number of movies instead of a pre declared fixed count.

Comments

1

Because of Movie has not got Genre you should cast Movie class to FeatureFilm class to work with Genre property. moviesArray is Movie array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.