adding objects to arrays/lists/collections

  • Thread starter Thread starter jg
  • Start date Start date
J

jg

Im not a beginner in vb.net, but I never asked myself what is the difference
between folowing lines of code:

1.)You add a object to an array/arraylist/collection (lets take arraylists)

myArrayList.add(myobject)

Question: what is the difference if you handle myobject form myArrayList
like this :

a)ctype(myArrayList(0),object).value = something (directly from array
list)

or like this

b)object.value = something

I hope you understand what Im trying to ask, what is the difference if you
handle a object that is stored in a arrayList direct a array (probably using
Ctype), or that you handle it directly after you add it to array (in both
cases).

Thanks
 
If I understand you correctly...

An arraylist is merely a collection of objects. It's a convenient way to
hold things, but it's simply a collection. However, you can shove all sorts
of things in the collection. If you CType it for instance, you can ensure
that a specific type is the only thing entered into your arraylist.
Consequently, you can Ctype it and access it's members.

I suspect you don't have Option Strict on, which you'll want to turn on and
you'll see the difference.

HTH,

Bill
 
Back
Top