468,321 Members | 1,809 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

Capacity of StringCollection

Hi.
I want to know why it is not possible to specify (or determine) the
capacity for a System.Collections.Specialized.StringCollection.

I guess the StringCollection would be the better choice over an
System.Collections.ArrayList
when there is only System.String instances to be stored in it.

The StringCollection provides only one undocumented constructur.

Thank you.
Nov 16 '05 #1
2 1680
Non settable lenght -- it's just the way a collection works.
You can always use an array (string[] stringArr)

Or implement your own collection that inherits from collectionbase and only
allows X elements to be added:

using System.Collections;

public myCollection : CollectionBase
{
private const MAXLENGTH = 50
public Add(srting newItem)
{
if(this.List.Count = MAXLENGTH)
thorw (new Exception("List maxlength encountered")
else
this.List.Add(newItem)
}

}

cheers,
mortb

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:kD*****************@news4.e.nsc.no...
Hi.
I want to know why it is not possible to specify (or determine) the
capacity for a System.Collections.Specialized.StringCollection.

I guess the StringCollection would be the better choice over an
System.Collections.ArrayList
when there is only System.String instances to be stored in it.

The StringCollection provides only one undocumented constructur.

Thank you.

Nov 16 '05 #2
> Dennis Myrénwrote:
I guess the StringCollection would be the better choice over an
System.Collections.ArrayList
when there is only System.String instances to be stored in it.


Just be aware that, contrary to what you might expect,
StringCollection is actually slower than ArrayList.

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jonathan | last post: by
2 posts views Thread by Dan | last post: by
3 posts views Thread by Ben Fidge | last post: by
1 post views Thread by Juan Francisco Figueroa Perez | last post: by
8 posts views Thread by Naz | last post: by
reply views Thread by Dinesh Rathi | last post: by
2 posts views Thread by =?Utf-8?B?YmlsbCB0aWU=?= | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.