471,325 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

System.Collections.Stack Maximum Size?

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

Feb 20 '06 #1
3 5098
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"sternr" wrote:
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

Feb 20 '06 #2
Peter Bromberg [C# MVP] <pb*******@yahoo.nospammin.com> wrote:
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....

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 20 '06 #3
True,
And since the stack pattern is a relatively simple one, certainly there is
no particular need to derive such a class from Stack. That is IMHO a good
subject for a blog item, I look forward to reading it.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jon Skeet [C# MVP]" wrote:
Peter Bromberg [C# MVP] <pb*******@yahoo.nospammin.com> wrote:
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....

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Feb 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Penn Markham | last post: by
9 posts views Thread by shine | last post: by
7 posts views Thread by amit.atray | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.