1-ARRAY LIST
AIM:
Using C# Programming, develop the program, which implements the properties and
methods in Array List.
SOURCE CODE:
using System;
using [Link];
namespace ArrayClass
{
class Arraylisteg
{
static void display(ArrayList array)
{
[Link]("Length of the Array List are {0}", [Link]);
[Link]("Elements in an Array are ...");
foreach(var elements in array)
{
[Link](elements);
}
}
static void addIndividual(ArrayList array)
{
[Link]("Enter the Element to Add :");
[Link]([Link]());
[Link]("Element Added Successfully");
}
static void addRange(ArrayList array)
{
[Link]("Enter the n value :");
int n = Convert.ToInt32([Link]());
Array ar = [Link](typeof(string), n);
for (int i = 0; i < n; i++)
{
[Link]("Enter the Values:");
[Link]([Link](), i);
}
[Link](ar);
[Link](" Values Inserted in Array List Successfully");
}
static void insertElement(ArrayList array)
{
[Link]("Enter the location to Insert:");
int n = Convert.ToInt32([Link]());
if (n > [Link])
{
[Link]("Not Sufficient Space to Insert :");
1|Page
}
else
{
[Link]("Enter the Value to Insert :");
string value = [Link]();
[Link](n, value);
[Link](" Values Inserted in Array List Successfully");
}
}
static void insertRange(ArrayList array)
{
[Link]("Enter the number of items to insert :");
int n = Convert.ToInt32([Link]());
Array ar = [Link](typeof(string), n);
[Link]("Enter the Location to Insert:");
int loc = Convert.ToInt16([Link]());
if (loc >= [Link])
{
[Link]("Not Sufficient Space to Insert :");
}
else
{
for (int i = 0; i < n; i++)
{
[Link]("Enter the Value to Insert :");
[Link]([Link](), i);
}
[Link](loc, ar);
[Link](" Values Inserted in Array List Successfully");
}
}
static void removeIndividual(ArrayList array)
{
string value;
[Link]("Enter the Element to Remove");
value= [Link]();
[Link](value);
[Link]("Element Deleted Successfully");
}
static void removeRange(ArrayList array)
{
[Link]("Enter the starting index :");
int loc = Convert.ToInt32([Link]());
[Link]("Enter the no of elements to Delete:");
int n = Convert.ToInt16([Link]());
if ((loc+n)>= [Link])
{
[Link]("Not Sufficient Space to Delete :");
}
else
{
[Link](loc, n);
[Link](" Values Deleted in Array List Successfully");
}
}
static void removeLoc(ArrayList array)
{
[Link]("Enter the Location to Delete");
2|Page
int loc = Convert.ToInt16([Link]());
if (loc < [Link])
{
[Link](loc);
[Link]("Element Deleted Successfully:");
}
else
{
[Link]("Not Sufficient Space to Delete :");
}
}
static void Search(ArrayList array)
{
[Link]("Enter the Element to Search :");
string value = [Link]();
if ([Link](value))
{
[Link]("Element Found Successfully ");
}
else
{
[Link]("Element Not Found ");
}
}
static void indexvalue(ArrayList array)
{
[Link]("Enter the value to Search:");
string value = [Link]();
int count= [Link](value);
if (count >= 0)
{
[Link]("Element is found at {0} Location ", count);
}
else
[Link]("Element is not found:");
}
public static void Main()
{
ArrayList array = new ArrayList(); // Definition and Initialization
int ch;
Array duparray = [Link](typeof(string), 10);
do
{
[Link](); // Clearscreen
[Link]("1- Add Individual Elements");
[Link]("2- Add Range of Elements");
[Link]("3- Insert Elements individually");
[Link]("4- Insert Range of Elements");
[Link]("5- Remove Individual Element");
[Link]("6- Remove Range of ELements");
[Link]("7- Remove Element at Location");
[Link]("8- Sort Elements");
[Link]("9- Reverse the Elements");
[Link]("10- Search");
[Link]("11- Clear the list");
[Link]("12- Duplicate the list");
[Link]("13- Index of Element");
3|Page
[Link]("14- Display");
[Link]("15- Exit");
ch = Convert.ToInt32([Link]());
switch (ch)
{
case 1:
addIndividual(array);
[Link]();
break;
case 2:
addRange(array);
[Link]();
break;
case 3:
insertElement(array);
[Link]();
break;
case 4:
insertRange(array);
[Link]();
break;
case 5:
removeIndividual(array);
[Link]();
break;
case 6:
removeRange(array);
[Link]();
break;
case 7:
removeLoc(array);
[Link]();
break;
case 8:
[Link]();
[Link]("Sorted Elements are ...");
display(array);
[Link]();
break;
case 9:
[Link]();
[Link]("Reversed Array are ..");
display(array);
[Link]();
break;
case 10:
Search(array);
[Link]();
break;
case 11:
[Link]();
[Link]("Elements of Array are Flushed ");
[Link]();
break;
case 12:
[Link](duparray);
[Link]();
foreach (string elements in duparray)
{
[Link](elements);
}
4|Page
[Link]();
break;
case 13:
indexvalue(array);
[Link]();
break;
case 14:
display(array);
[Link]();
break;
}
}while(ch!=15);
[Link]();
}
}
}
OUTPUT:
5|Page
6|Page
7|Page
8|Page
9|Page
10 | P a g e
11 | P a g e
12 | P a g e
13 | P a g e
14 | P a g e
15 | P a g e
16 | P a g e
17 | P a g e
RESULT:
Thus, Array list and its methods are implemented successfully.
18 | P a g e