Generics.cs
// 
//  Interface example by Josh Santomieri
//  Santomieri Systems - 08/28/2006
//

using System;
using System.Collections;

/// 
/// Represents a list.
/// 
/// The type of items the list will hold.
public class MyList : IEnumerable
{
	private ArrayList _list;

	/// 
	/// Creates a new MyList.
	/// 
	public MyList()
	{
		this._list = new ArrayList();
	}

	/// 
	/// Adds an item to the list.
	/// 
	/// The item to add to the list.
	public void Add(T item)
	{
		if (item != null)
		{
			this._list.Add(item);
		}
	}

	/// 
	/// Gets or sets the value at the specified index.
	/// 
	/// The index of the item to set.
	public T this[int i]
	{
		get	{ return (T)this._list[i]; }
		set	{ this._list[i] = value; }
	}

	/// 
	/// Gets the count of items in the list.
	/// 
	public int Count
	{
		get { return this._list.Count; }
	}

	/// 
	/// Get the enumerator for the list, Handles the IEnumerable Interface.
	/// 
	public IEnumerator GetEnumerator()
	{
		this._list.GetEnumerator();
	}
}

/// 
/// The example program class...
/// 
public class MyProgram
{
	/// 
	/// Main entry point for the progam.
	/// 
	public static void Main(string[] args)
	{
		// Create the lists, one that holds string, one that holds integers.
		MyList stringList = new MyList();
		MyList intList = new MyList();

		// Add a string to the list.
		stringList.Add("test");
		stringList.Add("test1");
		stringList.Add("test2");

		// Add an integer to the integer list.
		intList.Add(100);
		intList.Add(200);
		intList.Add(300);

		// Loop through the string list
		foreach(string s in stringList)
		{
			Console.WriteLine("String Value: " + s);
		}

		// Loop through the int list.
		foreach (int i in intList)
		{
			Console.WriteLine("Integer Value: " + i.ToString());
		}
	}
}