472,985 Members | 2,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1804
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Noo | last post by:
Hi. I've got some code that uses vectors fairly extensively and it needs to be efficient. Therefore I'm using reserve() quite a bit. However what other functions (are supposed to) change the...
3
by: Jonathan | last post by:
I tried using Type::GetType on S"System.Collections.Specialized.StringCollection", but it returned NULL. The only way it worked was when I used the fully qualified name, including the assembly...
2
by: Dan | last post by:
Hi, Is it possible to iterate through a StringCollection ? I have the following code but "row" always seems to contain the values of rowValues2 Thanks for any input, Danny
3
by: Ben Fidge | last post by:
Hi What are the options for sorting a StringCollection? I'm quite surprised that StringCollection doesn't have any sorting capability built in! Thanks Ben
1
by: Juan Francisco Figueroa Perez | last post by:
Hi all: I have a StringCollection property like this: public class FormExito : Form { ................ ................ private StringCollection FEditar;
8
by: Naz | last post by:
Hi, I am new in C# and converting a program from delphi to C#. I have to store a list of strings in memory and also need to save the strings to disk at the end. I use StringCollection and my...
0
by: Dinesh Rathi | last post by:
Hi I have a managed dll which I am using in my unmanaged application through its com interfaces. Now can I use StringCollection/ String class through com interfaces ? One of my class has a member...
2
by: eSapient | last post by:
I have a case where a C# dll is being consumed by an unmanaged C++ executable. One of the dll methods returns a StringCollection object. What are the requirements for the C++ executable in terms of...
2
by: =?Utf-8?B?YmlsbCB0aWU=?= | last post by:
Why should I use StringCollection as opposed to List<string>? Thank you.
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.