Main Site Documentation

Combining Arrays of strings together


#1

I have the two following arrays:

string[] files = Directory.GetFiles(e.Volume.RootDirectory);
                string[] folders = Directory.GetDirectories(e.Volume.RootDirectory);

I am searching for a method to combine these into a single array. Does anyone have a tip on how to do this?

Regards,
Aaron


#2
            string[] combined = new string[files.Length + folders.Length];
            Array.Copy(files, 0, combined, 0, files.Length);
            Array.Copy(folders, 0, combined, files.Length, folders.Length);

#3

This will also do the same job.

Choose one


var strArray  = Array.CreateInstance(typeof(string), files.Length + folders.Length);
OR
var strArray  = new string[files.Length + folders.Length];


files.CopyTo(strArray, 0);
folders.CopyTo(strArray, files.Length);


#4

wow, thats a relief, thanks both of you.