Tutorial - C# / Mono - Collections – ArrayList


Coding Friends Tutorial Index - > C# / Mono

Author Ian - Tutorial Posts = 62
Collections – ArrayList, the ArrayList is part of the Collections namespace. The ArrayList acts as the same as the array (here) apart from it allows other functional aspects to access the list of array.

Shall comment more on the different aspects in later tutorials, but basically there many different parts to a class that allow for better functionality e.g
1.       Interfaces = base of a class for strict implementation)
2.       IEnumerable (which is a interface) = means that you implement GetEnumerator aspects of a class, e.g. for the foreach command)
3.       Generics (which is part of .net 2) = Similar to templates (here) in c++ and also generics from Java).
4.       Etc. shall comment more on these.

This is the code
---
using System;

namespace ArrayListTest
{
class Program
{
static void Main(string[] args)
{
System.Collections.ArrayList arrayList = new System.Collections.ArrayList();
arrayList.Add(2);
arrayList.Add(3);
arrayList.Add("hi there");

foreach (object obj in arrayList)
Console.WriteLine(obj.ToString());
}
}
}
---
If you save as arraylisttest.cs, and then run, the output will be
2
3
hi there

It basically allows you to add in any object into the ArrayList, and since objects have the ToString() function, then it is able to print out the object, of course custom made objects will either display there type or the ToString() will have to be implemented.
Creation of cool tutorials :)
User Name Password
Copyright@CodingFriends, 2005-2006. All Rights Reserved.
Home | Forums | Tutorials | Users
RSS Feeds - Global Global CodingFriends RSS Feed - Tutorials Tutorials CodingFriends RSS Feed - Forums Forums CodingFriends RSS Feed - News News CodingFriends RSS Feed
Users
Login|Password problem| Register here

Tutorials
Tutorials Home| C/C++| C#/Mono| Java| Javascript| PHP| Ruby| SQL| (X)HTML/CSS| VB| Linux| Windows

Forum
Forum Home

Projects
3D Game

Site
Home| About me| Links| FAQ

Search