using System;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ArrayList myList = new ArrayList();
//Adding item type string
myList.Add("One");
myList.Add("Two");
myList.Add("Three");
//Adding item type integer
myList.Add(100);
myList.Add(200);
Console.WriteLine("\n Items in the list \n");
foreach (object item in myList)
{
Console.WriteLine(item);
}
// Using the insert method
myList.Insert(4, "Four");
Console.WriteLine("\n Items in the list after inserting new item in fourth place \n");
foreach (object item in myList)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}
using System;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ArrayList myList = new ArrayList();
Console.WriteLine("Initial status of List");
Console.WriteLine(" Count : {0}", myList.Count);
Console.WriteLine(" Capacity : {0}", myList.Capacity);
// Adding item type string
myList.Add("One");
Console.WriteLine("After adding one item in the list ");
Console.WriteLine(" Count : {0}", myList.Count);
Console.WriteLine(" Capacity : {0}", myList.Capacity);
myList.Add("Two");
myList.Add("Three");
// Adding item type integer
myList.Add(100);
myList.Add(200);
myList.Add(200);
Console.WriteLine("After adding six item in the list ");
Console.WriteLine(" Count : {0}", myList.Count);
Console.WriteLine(" Capacity : {0}", myList.Capacity);
myList.TrimToSize();
Console.WriteLine("Trim the list ");
Console.WriteLine(" Count : {0}", myList.Count);
Console.WriteLine(" Capacity : {0}", myList.Capacity);
Console.WriteLine("\n Items in the list \n");
foreach (object item in myList)
{
Console.Write(item+" ");
}
Console.ReadLine();
}
}
}
Property |
|
Methods |
|
using System;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Stack stackObj = new Stack();
stackObj.Push("One");
stackObj.Push("Two");
stackObj.Push("Three");
Console.WriteLine("\tDisplays the properties and values of the Stack\n");
Console.WriteLine("\tCount: {0}", stackObj.Count);
Console.Write("\tValues:");
foreach (Object obj in stackObj)
{
Console.Write(" {0}", obj);
}
Console.WriteLine("\n\n");
Console.Write("\tPopped Values from stack:\n");
while(stackObj.Count>0)
{
Console.Write("\t{0}", stackObj.Pop());
}
Console.ReadLine();
}
}
}
Property |
|
Methods |
|
using System;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Queue myQueue = new Queue();
myQueue.Enqueue("One");
myQueue.Enqueue("Two");
myQueue.Enqueue("Three");
myQueue.Enqueue("Four");
Console.WriteLine("\tDisplays the queue item\n");
while (myQueue.Count > 0)
{
object obj = myQueue.Dequeue();
Console.WriteLine("\t{0}", obj);
}
Console.ReadLine();
}
}
}