newbie What is best approach to do this?

J

Jeff

IDE: vs .NET 2003
OS: xp pro sp2

I need to create a class which can hold a x number of objects... Think of
the class as ArrayList, it can hold x number of objects... But using the
ArrayList doesn't suit entirely here, because I need to add some additional
properties / methods to this class....

I see two approaches to solve this (I'm not sure what is the best approach):
1) Create a new class which inheriating from ArrayList

2) Create a new class which implements interface (IList?)

What is best approach here?

If you suggest usig interface, what interface do you recommend me to use?
IList?

Jeff
 
L

Lebesgue

I suggest writing a class that encapsulates ArrayList
public class MyList
{
private ArrayList innerList;
public int AddFoo(Foo foo)
{
return innerList.Add(foo);
}

//add more methods and properties if you need
//you can also add some conversion operators if you need to supply this
class to methods where ArrayList is expected
}
 
R

Rick Elbers

Jeff,

I agree with the other poster that you might also consider to use
a class which has an arraylist.

And for your *properties* you might think about what this List Like
class is doing for you. Apart from multiset/multimaps I seldom need
other containers then the system.collections and
system.collections.specialized and only need those because I was used
to equal_range kind of syntax.

What is your class is doing with the number of objects might be an
interesting question.

Rick
 

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