userfriendly
Newcomer
- Joined
- May 3, 2010
- Messages
- 3
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:
however the following highlights "Movie" and generates the error "unable to cast object of type 'VideoStore.Game' to 'VideoStore.Movie" :
can anyone tell me why this is happening and how i can possibly fix it. thanks in advance
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:
Code:
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");
}
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
Last edited by a moderator: