iterating List<T> of a base class from derived class

P

phl

Hi,

I have a base class which inherits List<T>, how do I iterate this class
from the calling class? Do I have to use enumerater? Does anyone have
any code samples?

Thx
phl

base class:
abstract class FStatement<T> : List<T>
{

}

calling class:

class BStatement : FStatement<LI> //LI is another class see below
{
public BStatement()
{
this.dispdata();
}

public void dispdata()
{
//how do I do this?
}

}


class LI
{
private string sData1;

public string Data
{
get
{
return sData1;
}

set
{
sData1 = value;
}
}
}
 
P

Piotr Dobrowolski

phl napisał(a):
Hi,

I have a base class which inherits List<T>, how do I iterate this class
from the calling class? Do I have to use enumerater? Does anyone have
any code samples?

Thx
phl

base class:
abstract class FStatement<T> : List<T>
{

}

calling class:

class BStatement : FStatement<LI> //LI is another class see below
{
public BStatement()
{
this.dispdata();
}

public void dispdata()
{
//how do I do this?
}

}


class LI
{
private string sData1;

public string Data
{
get
{
return sData1;
}

set
{
sData1 = value;
}
}
}
[PD] Try:
foreach(LI l in this)
//display l;
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,
class BStatement : FStatement<LI>

So the calling class derive from your base class which in turn derive from
List , are you sure this is the intended way?

Anyway , you can do:

foreach( LI li in this )
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top