本文介绍了在foreach循环中加入字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string[] drives = Directory.GetLogicalDrives();
foreach (string d in drives)
{
string[] d1 = Directory.GetDirectories(d);
string[] pathlist = fde.Union(falaa).Union(d1).ToArray();
}
//fde is the nother path list
//falaa is the nother path list
* pathlist is the collection of all lists
//in path list i am not able to store the list
推荐答案
string[] drives = Directory.GetLogicalDrives();
string[] listPaths = fde.Union(falaa).ToArray();
foreach (string d in drives)
{
string[] d1 = Directory.GetDirectories(d);
string[] pathlist = listPaths.Union(d1).ToArray();
}
然后,我在组装时创建一个外部列表来保存数据:
Then, I'd create an external list to hold the data while I was assembling it:
string[] drives = Directory.GetLogicalDrives();
string[] listPaths = fde.Union(falaa).ToArray();
List<string> paths = new List<string>();
foreach (string d in drives)
{
string[] d1 = Directory.GetDirectories(d);
paths.AddRange(listPaths.Union(d1));
}
然后在循环外可以使用路径
集合。
The paths
collection is then available outside the loop.
这篇关于在foreach循环中加入字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!