Generic class are a bit different from a non generic class , there is an advantage of using this generic class , once I was too coding and that required inclusion of declaring a property in my program , but fortunately I did not require to set the values of properties , it was done in the constructor of the generic class .
using System;
using System.Collections.Generic;
using System.Text;
public class GenericList
Code:
{
private object[] elements;
private int cnt;
public GenList()
{
elmnts = new object[10];
}
public object this[int index]
{
get { return elmnts[index]; }
set { elements[index] = val; }
}
public void Add (object param)
{
if (cnt == elmnts.Length)
{
// Increase the
object[] tempArr = null ;
elmnts.CopyTo(tempArr,0);
elmnts = new object[cnt * 2];
elmnts = tempArr;
}
elmnts[cnt] = param;
cnt = cnt + +;
}
}
Bookmarks