using System;
using System.Collections;
namespace ArrayListCode
{
class Program
{
static void Main(string[] args)
{
#region ArrayList code starts here
ArrayList mylist = new ArrayList();
mylist.Add(7);
mylist.Add(1);
mylist.Add(0);
mylist.Add(3);
mylist.Add(23);
mylist.Add(35);
Console.WriteLine("Mylist has {0} no of items",mylist.Count);
Console.WriteLine("Mylist has capacity of {0}", mylist.Capacity);
mylist.Sort();
Console.WriteLine("The Array contains");
foreach(object o in mylist)
{
Console.WriteLine(o);
}
mylist.Reverse();
Console.WriteLine("The Array contains");
foreach (object o in mylist)
{
Console.WriteLine(o);
}
ArrayList myarr2 = new ArrayList();
myarr2.AddRange(new object[] { "Buffalo", "Cat", "Dog", "Eel", "Frog", "Gorilla"});
Console.WriteLine("The Array contains");
foreach (object o in myarr2)
{
Console.WriteLine(o);
}
myarr2.Insert(0, "Aye Aye");
Console.WriteLine("The Array contains");
foreach (object o in myarr2)
{
Console.WriteLine(o);
}
myarr2.AddRange(mylist);
Console.WriteLine("The Array contains");
foreach (object o in myarr2)
{
Console.WriteLine(o);
}
ArrayList mylist2 = myarr2.GetRange(0, 6);
Console.WriteLine("The Array contains here");
foreach (object o in myarr2)
{
Console.WriteLine(o);
}
Console.WriteLine("The Array contains");
foreach (object o in mylist2)
{
Console.WriteLine(o);
}
Console.WriteLine("The index of dog is {0}", myarr2.IndexOf("Dog"));
mylist2.RemoveAt(5);
Console.WriteLine("The Array contains");
foreach (object o in mylist2)
{
Console.WriteLine(o);
}
mylist2.RemoveRange(0, 5);
Console.WriteLine("The Array contains");
foreach (object o in mylist2)
{
Console.WriteLine(o);
}
string[] customers = {"Mikka", "Bob", "Sam", "Wilbert"};
mylist2.AddRange(customers);
foreach (object o in mylist2)
{
Console.WriteLine(o);
}
// ArrayList to array
string[] oldcustomers =(string[]) mylist2.ToArray(typeof(string));
#endregion
Console.ReadKey();
}
}
}
using System.Collections;
namespace ArrayListCode
{
class Program
{
static void Main(string[] args)
{
#region ArrayList code starts here
ArrayList mylist = new ArrayList();
mylist.Add(7);
mylist.Add(1);
mylist.Add(0);
mylist.Add(3);
mylist.Add(23);
mylist.Add(35);
Console.WriteLine("Mylist has {0} no of items",mylist.Count);
Console.WriteLine("Mylist has capacity of {0}", mylist.Capacity);
mylist.Sort();
Console.WriteLine("The Array contains");
foreach(object o in mylist)
{
Console.WriteLine(o);
}
mylist.Reverse();
Console.WriteLine("The Array contains");
foreach (object o in mylist)
{
Console.WriteLine(o);
}
ArrayList myarr2 = new ArrayList();
myarr2.AddRange(new object[] { "Buffalo", "Cat", "Dog", "Eel", "Frog", "Gorilla"});
Console.WriteLine("The Array contains");
foreach (object o in myarr2)
{
Console.WriteLine(o);
}
myarr2.Insert(0, "Aye Aye");
Console.WriteLine("The Array contains");
foreach (object o in myarr2)
{
Console.WriteLine(o);
}
myarr2.AddRange(mylist);
Console.WriteLine("The Array contains");
foreach (object o in myarr2)
{
Console.WriteLine(o);
}
ArrayList mylist2 = myarr2.GetRange(0, 6);
Console.WriteLine("The Array contains here");
foreach (object o in myarr2)
{
Console.WriteLine(o);
}
Console.WriteLine("The Array contains");
foreach (object o in mylist2)
{
Console.WriteLine(o);
}
Console.WriteLine("The index of dog is {0}", myarr2.IndexOf("Dog"));
mylist2.RemoveAt(5);
Console.WriteLine("The Array contains");
foreach (object o in mylist2)
{
Console.WriteLine(o);
}
mylist2.RemoveRange(0, 5);
Console.WriteLine("The Array contains");
foreach (object o in mylist2)
{
Console.WriteLine(o);
}
string[] customers = {"Mikka", "Bob", "Sam", "Wilbert"};
mylist2.AddRange(customers);
foreach (object o in mylist2)
{
Console.WriteLine(o);
}
// ArrayList to array
string[] oldcustomers =(string[]) mylist2.ToArray(typeof(string));
#endregion
Console.ReadKey();
}
}
}
Comments
Post a Comment