2

我想将新项目添加到字符串数组,或者我可以保留在列表中。有人可以展示如何做到这一点吗?

 string sourceDir = "C:\\Users\\ozkan\\Desktop\\foto\\"
 string[] picList;        
 string pattern = "*.jpg|*.png|*.gif";
 string[] filters = pattern.Split('|');

 foreach (string filter in filters)
 { 
    // I want to collect all files url in picList
    // Directory.GetFiles returns string array
    picList = Directory.GetFiles(sourceDir, filter);           
 }
4

1 回答 1

5

尝试 :

 string sourceDir = "C:\\Users\\ozkan\\Desktop\\foto\\"
 string[] picList;        
 string pattern = "*.jpg|*.png|*.gif";
 string[] filters = pattern.Split('|');
 picList =  filters .SelectMany(f=> Directory.GetFiles(sourceDir , f)).ToArray();          
于 2012-11-08T09:47:16.943 回答