Jump to content
Xtreme .Net Talk

userfriendly

Members
  • Posts

    3
  • Joined

  • Last visited

About userfriendly

  • Birthday 09/29/1990

userfriendly's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Eureka!! this works :D thankyou!
  2. thanks so much for the reply snarfblam :) really appreciate it i tried that and it does get rid of the error but it still leaves another problem. Sorry, I should have given more detail. The RentalItem class carries the properties title, itemId, and copies. then the Movie:RentalItem class carries the remaining properties specific to movies only these are: type, actors, director. If i use: foreach (RentalItem m in rentalList) { if (m is Movie) if (m.Director == director) ....etc then i get another error because RentalItem doesnt contain a definition for director... thats in Movie. Is there a way around this so that i can access the properties in 'Movie'??
  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: 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 :)
×
×
  • Create New...