C# 错误CS1503参数1:无法从';字符串[]和#x27;至';字符串';对于找到的文件夹

C# 错误CS1503参数1:无法从';字符串[]和#x27;至';字符串';对于找到的文件夹,c#,C#,所以我想知道在我的可执行文件位置找到的打印文件夹的名称 var foldersFound = Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory, "test", SearchOption.AllDirectories); Debug.Print(foldersFound); 然而,我得到一个错误的说法 Error CS1503 Argument 1: cannot convert from 'string[]'

所以我想知道在我的可执行文件位置找到的打印文件夹的名称

var foldersFound = Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory, "test", SearchOption.AllDirectories);
Debug.Print(foldersFound);
然而,我得到一个错误的说法

Error   CS1503  Argument 1: cannot convert from 'string[]' to 'string'  

我做错了什么?

执行foreach循环并打印foldersFound数组中的每个项目。GetDirectory的返回类型是数组,因此无法打印该数组

应该是这样的:

foreach(var folder in foldersFound){
   Debug.Print(folder);
}
getDirectory()返回一个字符串数组。如果要打印所有目录,则需要枚举它们

var foldersFound = 
Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory, "test", SSearchOption.AllDirectories);
    foreach (var folder in foldersFound)
    {
        Debug.Print(folder);
    }
或者可以使用string.Join()将它们连接起来

Debug.Print(string.Join(",",foldersFound));
我做错了什么

Debug.Print()
应为字符串类型,而不是字符串数组

var foldersFound = 
Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory, "test", SSearchOption.AllDirectories);

正在返回字符串数组。只需迭代字符串数组并逐个打印。

执行foreach循环并打印foldersFound数组中的每个项目。GetDirectory的返回类型是一个数组,因此您无法打印它。这似乎有效。谢谢也将此作为答案发布,请接受并乐于提供帮助。:)