System.Collections.Stack Maximum Size?

  • Thread starter Thread starter sternr
  • Start date Start date
S

sternr

Hey,
I'm using in my application a System.Collections.Stack object.
Is there a way to define a maximum size for the this stack object,
That when the max size is reached, the oldest value is deleted?
Thanks ahead

--sternr
 
The Stack class doesn't have an overloaded ctor or property to enforce this.
However, it does have a Count property, so it should be relatively easy to
write your own CustomStack class deriving from System.Collections.Stack that
does what you want.

Peter
 
Peter Bromberg said:
The Stack class doesn't have an overloaded ctor or property to enforce this.
However, it does have a Count property, so it should be relatively easy to
write your own CustomStack class deriving from System.Collections.Stack that
does what you want.

I would avoid inheritance in this case, and use composition instead.
Otherwise anything that expects normal stack behaviour could get
confused - I think this behaviour is sufficiently different from normal
stack behaviour to suggest a different class.

Then again, I tend to be against inheritance when it's not absolutely
called for anyway. I must get round to blogging about it some time....
 

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

Back
Top