Skip to main content
 首页 » 编程设计

c#之类型 'System.Collections.Generic.IEnumerable string>' 无法隐式转换为 'string []'

2024年02月06日23TianFang

我有一个问题,我想你可以帮助我,我有这段代码:

string[] A1 =  
    Directory 
        .GetFileSystemEntries(textbox2_f2.Text, "*", SearchOption.AllDirectories) 
        .Select(System.IO.Path.GetFileName); 
 
for (int i1 = 0; i1 < A1.Length; i1++) 
    listbox_2f.Items.Add(A1[i1]); 

这里是错误:

The type 'System.Collections.Generic.IEnumerable ' can not be implicitly converted to 'string []'. There is already an explicit conversion exists.

我该如何解决这个问题?

请您参考如下方法:

尝试:

Directory.GetFileSystemEntries(textbox2_f2.Text, "*", SearchOption.AllDirectories) 
    .Select(System.IO.Path.GetFileName) 
    .ToArray()