Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

C# - Difference between Array and Arraylist in C# with Example

Sep 17, 2013
Introduction:

Here I will explain difference between array and arraylist in c#.net with example.  

Description:


Arrays

Arrays are strongly typed collection of same datatype and these arrays are fixed length that cannot be changed during runtime. Generally in arrays we will store values with index basis that will start with zero. If we want to access values from arrays we need to pass index values.

Declaration of Arrays

Generally we will declare arrays with fixed length and store values like as shown below


string[] arr=new string[2];
arr[0] = "welcome";
arr[1] = "Aspdotnet-suresh";
In above code I declared array size 2 that means we can store only 2 string values in array.

Arraylists

Array lists are not strongly type collection. It will store values of different datatypes or same datatype. Array list size will increase or decrease dynamically it can take any size of values from any data type. These Array lists will be accessible with “System.Collections” namespace

Declaration of Arraylist

To know how to declare and store values in array lists check below code


ArrayList strarr = new ArrayList();
strarr.Add("welcome"); // Add string values
strarr.Add(10);   // Add integer values
strarr.Add(10.05); // Add float values
If you observe above code I haven’t mentioned any size in array list we can add all the required data there is no size limit and we will use add method to bind values to array list

Difference between Array and ArrayList

Arrays
ArrayLists
These are strong type collection and allow to store fixed length
Array Lists are not strong type collection and size will increase or decrease dynamically

In arrays we can store only one datatype either int, string, char etc…

In arraylist we can store all the datatype values
Arrays belong to System.Array namespace
Arraylist belongs to System.Collection namespaces



If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

33 comments :

PremNath said...

Very Useful !

Anonymous said...

Any noticeable performance difference? Obviously array is going to be faster but is it to a point that you should avoid ArrayList as often as you can?

Shri said...

thnx dude... these are the fadduuu definations...

Unknown said...

Simple and very clear article. Thank you very much anna.

Anonymous said...

understanding very easily,great job

Unknown said...

Gud Article brother thx

Unknown said...

nice sanpshot.....for increasing the kownlaged about array & array list ......

Revathy said...

Hi Suresh,

Very very ....useful to me :) keep rocking ......

Unknown said...

very super brother great work................................thanks

gsdg said...

sdgsde

Unknown said...
This comment has been removed by the author.
Anonymous said...

Nice article.......

Unknown said...

Very good info bro with simple example now i got the knowledge about arraylist thanks bro for posting this use full info

Unknown said...

nice article suresh.can u explain the jagged array?

Unknown said...

Nice Article can you explain the jagged Array concept?

SATEESH KUMAR.NANUBALA said...

Very NIce

Atul Chirame said...

In difference section,

In arrays we can store only one datatype either int, string, char etc…
In arraylist we can store all the datatype values

This is wrong difference. We can create array of any datatype.
e.g.
Home[] arr = { new Home(),new Home(),new Home()};

Nagi Reddy said...

why can't store the different types in array collection with object type.

object[] arr= new object[3]

with tis we can store different data types

Irfan Kumte said...

Thank u...explained simply and meticulously.

Anonymous said...

very usefull

Unknown said...

@Suresh,
Very nice article... keep it posting ........

Unknown said...

Owsm.........Simple and clear.......

Unknown said...

Arrays:

string[] arr=new string[2];
arr[0] = "Hello";
arr[1] = "Great job";

Arraylist:

ArrayList strarr = new ArrayList();
strarr.Add("welcome"); // Add string values
strarr.Add(10); // Add integer values
strarr.Add(10.05); // Add float values



Unknown said...

how can i add model values to array while the declaration of array.

Anonymous said...

really usefull!!!!!

Raushan said...

Good explained.

C# Blogger said...
This comment has been removed by the author.
C# Blogger said...

nice article

Unknown said...

Thanx Bro..Can you tell me how to use arraylist data

Saga Private Profile said...

Good Article

Jyoti Kumari said...

I was searching for conceptual difference and I found it. Thanks sir....

Unknown said...

we can have array of objects.. then what is the difference between the both ?
object[] objarray=new object[3];
ArrayList objlist = new ArrayList();

Unknown said...

how to use arraylist aa parameter?

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.