V
Venkatesh Bhupathi
Hi All,
I am trying to inherit the Generic IList<T> interface to form the
typed collection of objects of type T. Following is my sample code,
Public Class Record
{
public string name;
public string address;
Public Record(string sName, string sAddress)
{
this.name = sName;
this.address = sAddress;
}
}
Public Class Records<Record> : IList<Record>
{
public void Add(Record objRecord)
{
this.Add(objRecord);
}
public void Remove(int index)
{
this.RemoveAt(index);
}
......... with all the explicit member of IList interface
}
Implementation:
------------------------
Records objRecords = new Records();
objRecord.Add(new Record("xyz", "hyd"));
This code compiled fine, but at runtime the this.Add inside the
Records class has thrown StackOverFlowException. I am very new to
using Generics am confused with this error. Please help me understand
if what I am trying to implement is correct or is there any other way
to implement generic custom typed collection of objects.
Please let me know if you need any other information.
I am trying to inherit the Generic IList<T> interface to form the
typed collection of objects of type T. Following is my sample code,
Public Class Record
{
public string name;
public string address;
Public Record(string sName, string sAddress)
{
this.name = sName;
this.address = sAddress;
}
}
Public Class Records<Record> : IList<Record>
{
public void Add(Record objRecord)
{
this.Add(objRecord);
}
public void Remove(int index)
{
this.RemoveAt(index);
}
......... with all the explicit member of IList interface
}
Implementation:
------------------------
Records objRecords = new Records();
objRecord.Add(new Record("xyz", "hyd"));
This code compiled fine, but at runtime the this.Add inside the
Records class has thrown StackOverFlowException. I am very new to
using Generics am confused with this error. Please help me understand
if what I am trying to implement is correct or is there any other way
to implement generic custom typed collection of objects.
Please let me know if you need any other information.