Hi friends,

My requirement is to maintain a collection of products based upon categories and i have to retrieve that.For ex:i can retrieve different book names which are under the category Book..Say i can retrieve all mobile company names which are under the category Mobile.I was told to use collections here... What i suppose to do is to use list of arraylists...The list contains the category(Book) and the arraylist under that list contains the products(All book names under book)

  • ------>[Array lists under the list]

  • [Book]----->[TamilBook][EnglisgBook][MathsBook]

  • [Mobiles]--->[Nokia][SonyEricson][Motorola]
  • I need code in C#.Net...Any known friends help me...

  • Thanks in advance....sherin

Don't use ArrayList, for your example; better to use generics, as you know what datatypes to store.

Class Category {}
Class Book : Category{}
Class Mobile : Category{}

List<Book> books = new List<Book>();
List<Mobile> mobiles = new List<Mobile>();

List<Category> cat = new List<Book>();

Yeah, if you know what you're storing, use generics. You could have your top level actually be a Dictionary<string,List<BaseObject>>. the string part would act as the index (like "books," for example) so you could look it up later in the collection, then the list of BaseObjects could be the actual entries. If the list is really just strings then you'd use: Dictionary<string, List<string>> That way you don't have to muck around with Polymorphism.

This article has been dead for over six months. Start a new discussion instead.