5 Replies - 529 Views - Last Post: 27 June 2013 - 01:17 PM Rate Topic: -----

#1 Lee-Morgan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-June 13

Which To Use? List(Of T) Vs. Array

Posted 27 June 2013 - 01:53 AM

Hello,

I was just wondering whether I should use a List or an Array?

I have just started a new project and have come to the point where I need to decide which to use, it will be loaded with around 10,000 strings of 12 characters (product codes) I have experience with Arrays but have yet to use a List, I am not too concerned with speed, it does not need to be sorted or searched, I just want a simple way of looping and loading. Which of the two is the best for this purpose please?

Many Thanks
Lee

Is This A Good Question/Topic? 0
  • +

Replies To: Which To Use? List(Of T) Vs. Array

#2 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: Which To Use? List(Of T) Vs. Array

Posted 27 June 2013 - 02:10 AM

Hi,

An array is a fixed-size structure for storing multiple objects. A List is a simple collection, which you can think of as a dynamic array. A List allows you to add, insert and remove items and the collection will grow and shrink accordingly. With an array you create it with a specific number of elements and that size never changes.
Was This Post Helpful? 0
  • +
  • -

#3 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 433
  • View blog
  • Posts: 2,999
  • Joined: 12-January 10

Re: Which To Use? List(Of T) Vs. Array

Posted 27 June 2013 - 05:13 AM

we use both here at work---we use the lists when we are adding a lot of information to a data table in sql and we use arrays to iterate through said lists.
Was This Post Helpful? 0
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,499
  • Joined: 16-March 11

Re: Which To Use? List(Of T) Vs. Array

Posted 27 June 2013 - 07:32 AM

Whichever makes the job easier. In some cases I need to loop through using an index to do something with an item and in other cases I will do something with the object directly.
Was This Post Helpful? 0
  • +
  • -

#5 Lee-Morgan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-June 13

Re: Which To Use? List(Of T) Vs. Array

Posted 27 June 2013 - 08:48 AM

Many thanks for your replies.

So basically it doesn't matter which I use, just down to preference.
If anyone feels like explaining the benefits for using either that would be greatly appreciated.
Was This Post Helpful? 0
  • +
  • -

#6 dday9  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 86
  • Joined: 17-April 13

Re: Which To Use? List(Of T) Vs. Array

Posted 27 June 2013 - 01:17 PM

I will tell you that out of experience it all depends on the situation. If I need multiple dimensions, obviously the best way is an array. For example, a tic-tac-toe board:
Dim board(2, 2) As PictureBox
However, if I'm storing data, I'm going to use a list. For example, if I have a student class:
Dim classroom As New List(Of Student)


Both array's and list's have similar properties, and both(when use properly) have advantages over each other. You really have to evaluate the situation and decide on which is best. In your situation, I would use a list. At some point, that list of barcodes may need to grow or shrink, in which case an array wouldn't be the best option.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1