dynamic string[]

  • Thread starter Thread starter Spare Change
  • Start date Start date
S

Spare Change

I am told that I can have a dynamic or static string array.

So if I declare

string[] dynamic;

How do I add elements to dynamic and resize it ?
 
I went with a resizing routine.

foreach(Match m1 in mc1)
{
temp = new string[i+1];
anchors.CopyTo(temp,0);
temp[i++]=fileName+"#"+m1.Value.Substring(5,m1.Length-5);
anchors=temp;
}


Marijan said:
Try Sytem.Text.StringBuilder

Marijan


Spare Change said:
I am told that I can have a dynamic or static string array.

So if I declare

string[] dynamic;

How do I add elements to dynamic and resize it ?
 
Hi Cor:

Just to avoid confusion:
You declare a "static" string as

string[10] dynamic;

The above would lead to a compiler error.

This:

string[] dynamic = new string[10];

Would create a single dimensional array of string types.

--
Scott
http://www.OdeToCode.com


Spare,

You declare a "static" string as

string[10] dynamic;

A nice string with a fixed lenght with the name dynamic.

For dynamic array typen check all the iList collections (from which is the
fixex lenght array one)
http://msdn.microsoft.com/library/d...lrfsystemcollectionsicollectionclasstopic.asp

For even more have a look at the link iCollection on that bottom of that
page

I hope this helps?

Cor
 
I am told that I can have a dynamic or static string array.

So if I declare

string[] dynamic;

How do I add elements to dynamic and resize it ?

using System.Collections.Specialized;

....
StringCollection sc=new StringCollection();
sc.Add(str1);
....
//get a real string[] when done if needed

int len=sc.Count;
string[] strings=new string[len];
sc.CopyTo(strings,0);

Austin Ehlers
 
Yes, you are quite right.

But, I read that string[] can be dynamic.

I see no evidence, that once declared, that a primitive string[] can be
'ReDim'ed

:D

Scott said:
Hi Cor:

Just to avoid confusion:
You declare a "static" string as

string[10] dynamic;

The above would lead to a compiler error.

This:

string[] dynamic = new string[10];

Would create a single dimensional array of string types.

--
Scott
http://www.OdeToCode.com


Spare,

You declare a "static" string as

string[10] dynamic;

A nice string with a fixed lenght with the name dynamic.

For dynamic array typen check all the iList collections (from which is the
fixex lenght array one)
http://msdn.microsoft.com/library/d...lrfsystemcollectionsicollectionclasstopic.asp

For even more have a look at the link iCollection on that bottom of that
page

I hope this helps?

Cor
 
I don't know of any way in c# to implicitly resize a string array.
Consider using System.Collections.Speciallized.StringCollecion class.
It's a strongly-typed collection, something like an array list, but
for strings, so there is no performance hit for boxing.
 
Scott,

I should avoid writting C# code and not using the IDE.
(I write everything automaticly in a VBNet way)

:-)

Thanks,

Cor
 
I see no evidence, that once declared, that a primitive string[] can be
'ReDim'ed

I hope I am not wrong in this way, however as far as I know are there some
differences between the Array and in C# and VBNet.

In VBNet there is the Redim, however I would only using that when converting
a program from VB6 to VBNet and even than check for it and replace when that
is in it directly for a more dynamic one as I showed in a previous message
in this thread.

Redim seems to be a very performance consuming instruction.

Just my thought,

Cor
 
That is just mad!

The Devil said:
I went with a resizing routine.

foreach(Match m1 in mc1)
{
temp = new string[i+1];
anchors.CopyTo(temp,0);
temp[i++]=fileName+"#"+m1.Value.Substring(5,m1.Length-5);
anchors=temp;
}


Marijan said:
Try Sytem.Text.StringBuilder

Marijan


Spare Change said:
I am told that I can have a dynamic or static string array.

So if I declare

string[] dynamic;

How do I add elements to dynamic and resize it ?
 
System.Collections.Specialized.StringCollection should do. The interface is
very similar to string[] (except that Length is changed to Count) and you
can do Add()/Remove().

Jarek

Paul Wardle said:
That is just mad!

The Devil said:
I went with a resizing routine.

foreach(Match m1 in mc1)
{
temp = new string[i+1];
anchors.CopyTo(temp,0);
temp[i++]=fileName+"#"+m1.Value.Substring(5,m1.Length-5);
anchors=temp;
}


Marijan said:
Try Sytem.Text.StringBuilder

Marijan


I am told that I can have a dynamic or static string array.

So if I declare

string[] dynamic;

How do I add elements to dynamic and resize it ?
 
Back
Top