我如何使用IEnumerable <string>作为List?

时间:2016-03-05 20:26:15

标签: c# .net winforms

var ext = new List<string> { ".jpg", ".gif", ".png" };
var myFiles = Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories)
     .Where(s => ext.Any(e => s.EndsWith(e)));
CopyFilesToClipBoard()

方法CopyFilesToClipBoard()

public static string[] CopyFilesToClipBoard(List<string> file_list)
{
    foreach (string file_name in Directory.GetFiles(Application.StartupPath))
        file_list.Add(file_name);
    Clipboard.Clear();
    Clipboard.SetData(DataFormats.FileDrop, file_list.ToArray());
    string[] file_names = (string[])
    Clipboard.GetData(DataFormats.FileDrop);
    return file_names;
}

问题是CopyFilesToClipBoard应该获取List但是var myFiles是IEnumerable

1 个答案:

答案 0 :(得分:4)

您可以调用ToList方法:

CopyFilesToClipBoard(myFiles.ToList());