/*
*Name Space Required using System.Collections;
*This is an example of Arraylist
*/
ArrayList objArrlst = new ArrayList();
string[] arr = { "ID: 1","Domain: BNFS"};
objArrlst.Add("Name: Bimlesh Singh");
objArrlst.AddRange(arr);
objArrlst.Insert(0, "EMP Detail");
/*method 1.
* This is a way of Iterating through a Arraylist.
* With the help of IEnumerator Interface's GetEnumerator method which returns a Interface IEnumerator.
*/
objArrlst.Add(1);
IEnumerator Ienum = objArrlst.GetEnumerator();
while (Ienum.MoveNext())
{
Console.WriteLine(Ienum.Current );
}
/*method 1.
* This is a way of Iterating through a Arraylist with the help of Foreach loop.
* if we use foreach (String objstr in objArrlst)below it will through a casting error.
*/
foreach (Object objstr in objArrlst)
{
Console.WriteLine(objstr);
}
objArrlst.Remove(1);
/*
* Comparer Class is used for in the ArrayList.Sort method to do the default sorting.
* It is the default implementation of the IComparer implementation
*/
objArrlst.Sort();
Console.Read();
No comments:
Post a Comment