0

I'm getting the error: error CS0266: Cannot implicitly convert type System.Collections.Generic.IEnumerable<string>' tostring[]'. An explicit conversion exists (are you missing a cast?) Where do I cast?

IEnumerator LoadAllImages()
{
    string[] ARCTOPITHECUSPaths = Directory.GetFiles(@"/Users/kenmarold/Screenshots/ARCTOPITHECUS/", "*.png");      // get every file in chosen directory with the extension.png
    string[] GULONPaths = Directory.GetFiles(@"/Users/kenmarold/Screenshots/GULON/", "*.png");                      

    galleryArray = ARCTOPITHECUSPaths.Concat(GULONPaths);
greyBow
  • 1,298
  • 3
  • 28
  • 62

1 Answers1

1

Concat returns IEnumerable. To convert it to array do following:

galleryArray = ARCTOPITHECUSPaths.Concat(GULONPaths).ToArray();
lukbl
  • 1,763
  • 1
  • 9
  • 13
  • Thank you! How would I concat more than one additional array? I tried string[] galleryPaths = filePaths.Concat(gulonPaths, scythianWolfPaths).ToArray(); but that didn't work. – greyBow Jul 24 '15 at 14:12
  • 1
    Just chain calls like this: array0.Concat(array1).Concat(array2).Concat(array3).ToArray() – lukbl Jul 24 '15 at 14:21
  • Perfect! Thank you for the help! – greyBow Jul 24 '15 at 14:26
  • Last question, when I get files with this line: arctopithecusPaths = Directory.GetFiles(@"/Users/kenmarold/Screenshots/ARCTOPITHECUS/", "*.jpg"); is there a way to get files with multiple file extensions? I want to get both jpg and png but didn't know how to do that in a single line. Or do I just need to add another line? arctopithecusPaths = Directory.GetFiles(@"/Users/kenmarold/Screenshots/ARCTOPITHECUS/", "*.png"); – greyBow Jul 24 '15 at 14:28
  • 1
    Some solutions to this are in this question: http://stackoverflow.com/questions/7039580/multiple-file-extensions-searchpattern-for-system-io-directory-getfiles – lukbl Jul 24 '15 at 14:37