我想将新项添加到字符串数组中,或者我可以保留在List中。有人可以说明如何做到这一点吗?
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);
}
答案 0 :(得分: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();