CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Posts
    37

    List Arraylist Question

    Hi!
    I've been wondering why you can define and what is the difference when you create next:

    List <Car> cars=new ArrayList<Car> ;

    OR

    List cars=new Arraylist();

    so these both works but whats the real difference and when it matters that you define
    List and ArrayList with <Car> ie. <E> because you can use it without too.

    Thanks!

  2. #2
    Join Date
    Apr 2001
    Location
    South Africa, Jo'burg
    Posts
    680

    Re: List Arraylist Question

    Hi,

    <Car> is a generic, and by using it you are telling the VM that all objects inside the List will be of type Car, so when you retrieve an object from the List you won't have to cast it to a Car object. If you didn't use the <Car> generic then you would have to cast objects to Car in order to use them since the list will only return objects of type Object.

    Have a look HERE for a fuller explanation.

    Hope this helps
    Byron Tymvios

    Please use [ CODE ] and [/ CODE ] tags when posting code! See THIS on how to use code tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured