Add Method In ArrayList Class
Syntax for Add Method is :- Add(valueofanytype)
--------------------------------------------------------------------------------------------------------
using System;
using System.Collections;
public class AddMethod
{
public static void Main()
{
ArrayList alist = new ArrayList();
Console.WriteLine("Initial Count {0} and Capacity {1} " ,alist.Count,alist.Capacity);
Console.WriteLine("-----------------------------------------------");
Console.WriteLine("Adding 3 Elements");
alist.Add('C');
alist.Add('A');
alist.Add('E');
Console.WriteLine("Count {0} and Capacity {1}: " ,alist.Count, alist.Capacity);
for(int i=0;i<alist.Count;i++)
{
Console.Write(alist[i] + " ");
}
Console.WriteLine();
Console.WriteLine("-----------------------------------------------");
Console.WriteLine("Adding 20 more elements");
for(int i=0;i<20;i++)
{
alist.Add((char)('a' + i));
}
Console.WriteLine("Count {0} and Capacity {1}: " ,alist.Count, alist.Capacity);
foreach(char c in alist)
{
Console.Write(c + " ");
}
}
}
--------------------------------------------------------------------------------------------------------
Add Method In ArrayList Class
Reviewed by Baljeet Singh
on
10:08
Rating:
No comments: