any special benefits in using 'collections' rather than using 'arrays'?
thanks
Printable View
any special benefits in using 'collections' rather than using 'arrays'?
thanks
Arrays are dying in .NET...They are being replaced by Dictionary Objects.
A collection is not far removed from an array. There are numerous objects that inherit or implement ICollection and thus could be considered collections like ArrayList. Generally speaking collections differ from arrays in that they are easier to manipulate or add/remove items from.
That's surprising....
I just started on a project and I am using arraylist heavily...
I hope you didn't mean arraylist ..
nath
what's the difference between a dictionary object and a collection?
Don't worry , ;) ArrayList is perfect solution over array . I had to use it in a way that holds 10,000 values in one arraylist and working nice . Performance is good too . faster in iteration and retrieving .Quote:
Originally posted by bnathvbdotnet
That's surprising....
I just started on a project and I am using arraylist heavily...
I hope you didn't mean arraylist ..
nath
A collection is a type of dictionary object, there are many others such as sortedlists, arraylists, queues. They are a fundamental thing to learn, so get reading, there are 100s of examples.Quote:
Originally posted by nswan
what's the difference between a dictionary object and a collection?
There is also a vb.collection, which is different from the dictionary object set. Its easier to use, but slower.
Be warned tho, the hashtable in .net2002 (being framework 1.0) has a memory problem. Its ok until you add 100,000s of objects every hour :) for days.
Heres a snippet of code that uses the dictionary base object and acts exactly like the VB.Collection, it automatically changes the objects to the correct type when reading. Use the
For each Thing in MyNewCollection.Values << note the extra part to loop through.
Code:
<Serializable()> Friend Class MyCollection : Inherits Collections.DictionaryBase
Friend Sub Add(ByVal ClassRef As clsMyClass, Optional ByVal Key As String = "")
MyBase.Dictionary.Add(Key, ClassRef)
End Sub
Friend Sub Remove(ByVal Key As String)
MyBase.Dictionary.Remove(Key)
End Sub
Friend Function Item(ByVal Key As String) As clsActionsExpand
Return DirectCast(MyBase.Dictionary.Item(Key), clsMyClass)
End Function
Public ReadOnly Property Values() As ICollection
Get
Return InnerHashtable.Values
End Get
End Property
End Class