Search the Community
Showing results for tags 'invalid'.
-
hi, im trying to make a simple search tool for an array read from a .txt file. The .txt file has two types of items, movies and games and looks like this for example: M0001;DVD;The Hours;Nicole Kidman, Meryl Streep;Stephen Daldry;10 G0004;PlayStation 2;Spy Hunter 2;12 the file is read in a FileReader class which has an if statement specifying whether the item is a movie or a game. The 'Movie' and 'Game' classes are inherited from a class called 'RentalItem'. In the method im writing that does the actual search i have this and it works fine: rentalList = new ArrayList(); rentalList = FileReader.readRentalItems(); public string QueryMovieItem (string title, string actor, string director) foreach (RentalItem m in rentalList) { if (m.Title == title) sb.Append(m.ItemId + ", " + m.Title + ", copies: " + m.Copies + "\n\n"); }[/Code] however the following highlights "Movie" and generates the error "unable to cast object of type 'VideoStore.Game' to 'VideoStore.Movie" : [code]foreach (Movie m in rentalList) { if (m.Director == director) sb.Append(m.ItemId + ", " + m.Title + ", copies: " + m.Copies); } can anyone tell me why this is happening and how i can possibly fix it. thanks in advance :)