What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 7035 |  Welcome, Guest!   Register  Login
 Home > Forums > C# > How to use arraylist in c#? ...
Susanthampy

How to use arraylist in c#?

Replies: 10 | Posted by: Susanthampy on 6/10/2011 | Category: C# Forums | Views: 19884 | Status: [Member] [MVP] | Points: 10  


How to use arraylist in c#....

Give some examples....

Regards,
Susan


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Sksingh
Sksingh  
Posted on: 6/10/2011 1:05:13 AM
Level: Starter | Status: [Member] | Points: 25

Hi Susan,

See below example about arraylist .

using System;

using System.Collections;

class Program
{
static void Main()
{
//
// Create an ArrayList with two values.
//
ArrayList list = new ArrayList();
list.Add(3);
list.Add(4);
//
// Second ArrayList.
//
ArrayList list2 = new ArrayList();
list2.Add(5);
list2.Add(6);
//
// Add second ArrayList to first.
//
list.AddRange(list2);
//
// Display the values.
//
foreach (int i in list)
{
Console.WriteLine(i);
}
}
}

Output

3
4
5
6



GetRanage


using System;

using System.Collections;

class Program
{
static void Main()
{
//
// Create an ArrayList with 4 strings.
//
ArrayList list = new ArrayList();
list.Add("DotNet");
list.Add("Java");
list.Add("PHP");
list.Add("SQL");
//
// Get last two elements in ArrayList.
//
ArrayList range = list.GetRange(2, 2);
//
// Display the elements.
//
foreach (string val in range)
{
Console.WriteLine(val);
}
}
}
OutPut:
PHP
SQL


same way have a look at all methods of arraylist.

Regards,
Sunil

Susanthampy, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Nithadeepak
Nithadeepak  
Posted on: 6/10/2011 1:05:48 AM
Level: Bronze | Status: [Member] | Points: 25

Susan,
Refer,
http://www.dotnetperls.com/arraylist

Nitha Deepak

Susanthampy, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Susanthampy
Susanthampy  
Posted on: 6/10/2011 3:19:30 AM
Level: Bronze | Status: [Member] [MVP] | Points: 25

Hi Sunil

thanks for ue reply

Regards,
Susan

Susanthampy, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Susanthampy
Susanthampy  
Posted on: 6/10/2011 3:19:58 AM
Level: Bronze | Status: [Member] [MVP] | Points: 25

Hi Nitha,

thanks for ur reply

Regards,
Susan

Susanthampy, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Annupandey
Annupandey  
Posted on: 6/15/2011 6:18:02 AM
Level: Starter | Status: [Member] | Points: 50

Resolved

ArrayList is a class that t belongs to System.Collection.It can accept all the data types into it..It is defined by four blocks by default.
eg.
class c
{
Static void Main(String [ ]args)
{
ArrayList ar = new ArrayList();

ar.add("rek");

ar.add(3);

ar.add(33.3f);

Console.Write(ar);

}
}

output-
rek
3
33.3

Susanthampy, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Lakn2
Lakn2  
Posted on: 6/15/2011 7:51:22 AM
Level: Starter | Status: [Member] | Points: 25

Susanthampy, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Susanthampy
Susanthampy  
Posted on: 6/15/2011 7:53:47 AM
Level: Bronze | Status: [Member] [MVP] | Points: 25

Hi Annu,

Thanks for ur reply

Regards,
Susan

Susanthampy, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Susanthampy
Susanthampy  
Posted on: 6/15/2011 7:54:11 AM
Level: Bronze | Status: [Member] [MVP] | Points: 25

Hi Lakn,

thanks for ur reply

Regards,
Susan

Susanthampy, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Rajashekaranmec
Rajashekaranmec  
Posted on: 6/28/2012 7:27:09 AM
Level: Starter | Status: [Member] | Points: 25

ArrayList list = new ArrayList();
list.Add("rajan");
list.Add(20000);
string[] stringList = list.OfType<string>().ToArray();
Int32[] intList = list.OfType<Int32>().ToArray();
int n1 = intList[0];
Console.WriteLine(n1);

output :20000

Susanthampy, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Aksrinivas84
Aksrinivas84  
Posted on: 7/11/2012 6:35:19 AM
Level: Starter | Status: [Member] | Points: 25

//First of all create an object for the ArrayList Class

// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add( "My" );
myAL.Add( "Name" );
myAL.Add( "is" );
myAL.Add( "Srinivas" );
//Now once the list is created try to display the list
foreach (string val in myAL)
{
Console.WriteLine(val);
}

Susanthampy, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

Found interesting? Add this to:


 Latest Posts

Write New Post | More ...

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/26/2013 1:38:44 AM