|
Sunday, September 30, 2007
GeekInterview.com Weekly Digest, September 30th, 2007
Monday, September 24, 2007
Difference between ArrayList and Array C#
ArrayList is a mre like a vector. (A re-sizeable array). It is a collection and stores any value as an object.
An arraylist grows as you add items to it and does not have to be redimmed the
allow additional elements. Arraylists are sortable, searchable, etc - they
are far superior to arrays.
When you have a fixed array, there is in use no difference.
Arrays cannot be changed in size at runtime (except using 'ReDim' which
will create a new array, copy the old array in the new array and destroy
the old array). The arraylist is more dynamic, you can add and remove
items without loosing performance. if 'ReDim' is followed by a 'Preserve'
ArrayList is an extended managment of Arrays....
ArrayList can hold objects(custom...or...defined)
say i have an object user with properties name and email
my AraayList can hold users object...means one or more
Array is Type specific....so can hold Types like int, string etc......
ArrayList class implements IList interface using an array.
Advantages:
Its capacity is increased if required as objects are added to it. So it frees
programmer from the worries of array overflow.
Provides methods to perform common operations -- append, insert,
remove, replace etc.
There is no restriction on the type of objects which can be added to an
arraylist. First object could be a string, second a double, third a user
defined object and so on.
ArrayList can be made read only after adding elements to prevent
unintentional modifications.
It provides an overloaded method to perform binary search on its objects.
ArrayList is also a datastructure in dotnet which contain data in it thr
major difference in between array and arraylist is insertion and deletion of
data In ArrayList we can eaisely insert Data at a particular location while
in array it is not possibel
Array is for homogeneous data. i.e data of same data type.
Whereas Arraylist is for Heterogeneous data.The data in the arraylist need
not be of same data type.
Also it(arraylist) can store objects. say objects of type account.
Suppose that u r using an array of intgers.Which may contain any numer
of integers which you know only at runtime.
So while coding u cannot specify the size of the Array.
Array list is used to solve this problem.
It has a default size(16 items).
if u have even 1 item the size will be 16.
After 16 if u add another item, the size increases to 32.
i.e the arrayList size can be increased dynamically
Sunday, September 23, 2007
GeekInterview.com Weekly Digest, September 24th, 2007
|