Replies |
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
Posted on: 6/10/2011 1:05:48 AM
|
Level: Bronze | Status: [Member] | Points: 25
|
Susanthampy, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
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
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
Posted on: 6/15/2011 6:18:02 AM
|
Level: Starter | Status: [Member] | Points: 50
|
 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
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
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
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
|
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
|
//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
|