- Home /
C# List of Files
Hi everyone, is there a way to make a List of Files instead of an array? I want to be able to add and remove from the list. I tried creating one but I keep getting this error cannot convert type string[] to list
//cannot convert string[] to list <string>
public list <string> Examplefiles = Directory.GetFiles(Application.dataPath);
Comment
Looks like you're defining Examplefiles as both an array and a list. But I don't know, you need to post up the whole script :)
Answer by liszto · Dec 28, 2012 at 01:11 AM
It's because Directory.GetFiles(string) return an array of strings.
So you can do this :
public string[] exampleFiles = Directory.GetFiles(Application.dataPath);
List<string> lstExampleFiles = new List<string>();
lstExampleFiles.AddRange( exampleFiles );
I think this can work
Some documentation on AddRange here
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Issues outputting a list of strings 1 Answer
Multiple Cars not working 1 Answer
Making a camera list 1 Answer
C# Randomly Adding Elements from stringListA to stringListB 1 Answer