Difference between ArrayList and List<object> ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Murat  Ozgur

    #1

    Difference between ArrayList and List<object> ?

    Hello,

    Is there any difference between ArrayList and List<object? Which
    one should I use ?

    Thanks.

  • MrAsm

    #2
    Re: Difference between ArrayList and List&lt;object& gt; ?

    On 20 Oct 2006 01:31:11 -0700, "Murat Ozgur" <muratozgur@gma il.com>
    wrote:
    Is there any difference between ArrayList and List<object? Which
    >one should I use ?
    I think List< object should be better, because it uses generics; so
    it is type safer than ArrayList (in which you can put everything
    derived from base object class).

    Comment

    • Chris Fulstow

      #3
      Re: Difference between ArrayList and List&lt;object& gt; ?

      Not much difference really, I'd probably use List<Objectbeca use then
      it's clear to other people that your intention was to store a list of
      Objects (or various derivative types), rather than a list of some other
      specific type that would always need explicitly casting.

      --
      Chris Fulstow
      MCP, MCTS



      Murat Ozgur wrote:
      Hello,
      >
      Is there any difference between ArrayList and List<object? Which
      one should I use ?
      >
      Thanks.

      Comment

      • Dustin Campbell

        #4
        Re: Difference between ArrayList and List&lt;object& gt; ?

        Is there any difference between ArrayList and List<object? Which
        one should I use ?
        I'd choose to use List<objectbeca use of the improved APIs on List<object>
        that aren't available on ArrayList.

        Best Regards,
        Dustin Campbell
        Developer Express Inc.


        Comment

        • Brian Gideon

          #5
          Re: Difference between ArrayList and List&lt;object& gt; ?

          Murat,

          I like the extended API of List<T>. Also, I wouldn't be surprised if
          they use different growth algorithms.

          Brian

          Murat Ozgur wrote:
          Hello,
          >
          Is there any difference between ArrayList and List<object? Which
          one should I use ?
          >
          Thanks.

          Comment

          • Angel Of Death

            #6
            Re: Difference between ArrayList and List&lt;object& gt; ?

            * Murat Ozgur wrote:
            Hello,
            >
            Is there any difference between ArrayList and List<object? Which
            one should I use ?
            >
            List<objectis type safe and more efficient since it doesn't require
            boxing operations (converting a value type to a reference type, and vice
            versa) so it could be more efficient depending on what you store in your
            list.

            Comment

            • Bill Butler

              #7
              Re: Difference between ArrayList and List&lt;object& gt; ?

              "Angel Of Death" <afklj@23o.1f.c o.ukwrote in message
              news:ehd5ev$50n $2@custnews.inw eb.co.uk...
              >* Murat Ozgur wrote:
              >Hello,
              >>
              > Is there any difference between ArrayList and List<object? Which
              >one should I use ?
              >>
              >
              List<objectis type safe and more efficient since it doesn't require
              boxing operations (converting a value type to a reference type, and
              vice
              versa) so it could be more efficient depending on what you store in
              your
              list.
              Claiming that "List<objec tis type safe" is sort of silly.
              Since it has a type of object that kind of wipes out type saftey since
              everything is an object.

              A better overall suggestion would be to use List<SomeType>. Then you can
              talk about type safe.

              Bill



              Comment

              • Mark Rae

                #8
                Re: Difference between ArrayList and List&lt;object& gt; ?

                "Angel Of Death" <afklj@23o.1f.c o.ukwrote in message
                news:ehd5ev$50n $2@custnews.inw eb.co.uk...
                List<objectis type safe
                Of course it isn't!

                List<stringis type-safe, List<SqlParamet eris type-safe, but List<object>
                *clearly* isn't... :-)

                List<objectobjL ist = new List<object>;
                objList.Add(new string);
                objList.Add(new int);

                etc


                Comment

                • Göran Andersson

                  #9
                  Re: Difference between ArrayList and List&lt;object& gt; ?

                  MrAsm wrote:
                  On 20 Oct 2006 01:31:11 -0700, "Murat Ozgur" <muratozgur@gma il.com>
                  wrote:
                  >
                  > Is there any difference between ArrayList and List<object? Which
                  >one should I use ?
                  >
                  I think List< object should be better, because it uses generics; so
                  it is type safer than ArrayList (in which you can put everything
                  derived from base object class).
                  >
                  No, there is no difference in type safety. A reference to an object is
                  not more type safe just because you use generics.

                  Comment

                  • Peter Duniho

                    #10
                    Re: Difference between ArrayList and List&lt;object& gt; ?

                    "Göran Andersson" <guffa@guffa.co mwrote in message
                    news:eOGS1jY9GH A.3396@TK2MSFTN GP04.phx.gbl...
                    >I think List< object should be better, because it uses generics; so
                    >it is type safer than ArrayList (in which you can put everything
                    >derived from base object class).
                    >
                    No, there is no difference in type safety. A reference to an object is not
                    more type safe just because you use generics.
                    I think what he means is that an ArrayList can store multiple types, and
                    there's no checking to ensure that every element of the array is the same
                    type as every other element.

                    Perhaps a more significant benefit would be "type convenient". :)

                    As you note, C# is type safe no matter how you store a reference. But one
                    nice thing about the generic types is that because the type is explicitly
                    stated with the collection, you don't need to cast things as they are
                    referenced from the collection.

                    Pete


                    Comment

                    • Göran Andersson

                      #11
                      Re: Difference between ArrayList and List&lt;object& gt; ?

                      Peter Duniho wrote:
                      "Göran Andersson" <guffa@guffa.co mwrote in message
                      news:eOGS1jY9GH A.3396@TK2MSFTN GP04.phx.gbl...
                      >>I think List< object should be better, because it uses generics; so
                      >>it is type safer than ArrayList (in which you can put everything
                      >>derived from base object class).
                      >No, there is no difference in type safety. A reference to an object is not
                      >more type safe just because you use generics.
                      >
                      I think what he means is that an ArrayList can store multiple types, and
                      there's no checking to ensure that every element of the array is the same
                      type as every other element.
                      The exact same is true for List<objecttoo.
                      Perhaps a more significant benefit would be "type convenient". :)
                      >
                      As you note, C# is type safe no matter how you store a reference. But one
                      nice thing about the generic types is that because the type is explicitly
                      stated with the collection, you don't need to cast things as they are
                      referenced from the collection.
                      Yes, that is true for a list of a specific type, like List<int>, but not
                      for List<object>.

                      Comment

                      • Göran Andersson

                        #12
                        Re: Difference between ArrayList and List&lt;object& gt; ?

                        Please use cross posting instead of doing separate postings of the same
                        question in a lot of newsgroups.

                        Comment

                        • Peter Duniho

                          #13
                          Re: Difference between ArrayList and List&lt;object& gt; ?

                          "Göran Andersson" <guffa@guffa.co mwrote in message
                          news:eQAoYCZ9GH A.4712@TK2MSFTN GP03.phx.gbl...
                          >I think what he means is that an ArrayList can store multiple types, and
                          >there's no checking to ensure that every element of the array is the same
                          >type as every other element.
                          >
                          The exact same is true for List<objecttoo.
                          Sorry...read "List<objec t>" as "List<T>".


                          Comment

                          • Angel Of Death

                            #14
                            Re: Difference between ArrayList and List&lt;object& gt; ?

                            * Mark Rae wrote:
                            "Angel Of Death" <afklj@23o.1f.c o.ukwrote in message
                            news:ehd5ev$50n $2@custnews.inw eb.co.uk...
                            >
                            >
                            >>List<object is type safe
                            >
                            >
                            Of course it isn't!
                            I meant list<some_type! oops.

                            Comment

                            Working...