Prepending a string to a string[]

D

David P. Donahue

There must be something I'm missing, but is there an easy way to add a
given string as the first element in a string[] after the string[] is
created (from, say, a Directory.GetFiles function call)?


Regards,
David P. Donahue
(e-mail address removed)
 
J

Jon Skeet [C# MVP]

David P. Donahue said:
There must be something I'm missing, but is there an easy way to add a
given string as the first element in a string[] after the string[] is
created (from, say, a Directory.GetFiles function call)?

No. Arrays are fixed size. You need to create a new array with the
bigger size, put the string into the first element, then copy the array
into the rest.
 

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

Top