Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hai,

How to store and retrive the values in ArrayList using C#?

Thanks in advance.
Posted

ArrayList a = new ArrayList();
//Storing the valus in the ArrayList
a.Add("a");
a.Add("b");
a.Add("c");
a.Add("d");
a.Add("e");

//Retrieving the recoprds from the ArrayList
foreach (string s in a)
{
Console.WriteLine(s);
}
 
Share this answer
 
Comments
Sajith Dilhan 23-Nov-11 0:47am    
This is the simplest solution :)
LanFanNinja 23-Nov-11 0:55am    
+5 I would however recommend that the OP use a generic List<t> instead.
See SAKryukov's solution(solution 1) in the link below for a good explanation of why I say this.
http://www.codeproject.com/Answers/288273/add-change-and-delete-in-my-ArrayLis/?cmt=181392#answer1
 
Share this answer
 
Try this
ArrayList in C#
 
Share this answer
 
Comments
gaurish thakkar 9-Aug-12 5:53am    
HOw can one store two values in a single arraylist element


like arr.add("1","2");
arr.add("3","4");

so i can fetch them later as pair
arraylist arrlist = new arraylist();
arrlist.add("1");
arrlist.add("2");

for (int i=0 ; i<= arrlist.count-1 ;i++)
{
respose.write(arrlist[i].totsring());
}
 
Share this answer
 
Comments
CHill60 13-Feb-14 15:30pm    
Question is over 2 years old and your "solution" won't even compile
C#
ArrayList cblSelections = new ArrayList();
   foreach (ListItem item in AccCheckBoxList.Items)
   {
       if (item.Selected)
       {
           cblSelections.Add(item.Value);
       }
   }
 
Share this answer
 
Comments
CHill60 13-Feb-14 15:31pm    
Question is over 2 years old and your solution only demonstrates how to add items to the array list from a list box - incomplete and somewhat off topic

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900