Directory.EnumerateFiles和Directory.GetFiles之间有什么区别? [英] What is the difference between Directory.EnumerateFiles vs Directory.GetFiles?
问题描述
code> Directory.EnumerateFiles vs GetFiles
?
What is the difference between Directory.EnumerateFiles
vs GetFiles
?
显然,一个返回一个数组,另一个返回Enumerable。
Obviously one returns an array and the other return Enumerable.
还有什么?
推荐答案
从文档:
EnumerateFiles和GetFiles方法的区别如下:当您使用EnumerateFiles时,可以在返回整个集合之前开始枚举名称集合;当您使用GetFiles时,您必须等待返回所有名称的数组,然后才能访问数组。因此,当您使用许多文件和目录时,EnumerateFiles可以更有效率。
The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array. Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
所以基本上, EnumerateFiles
返回一个 IEnumerable
,可以稍微评估一下,而 GetFiles
返回一个 string []
必须完全填充才能返回。
So basically, EnumerateFiles
returns an IEnumerable
which can be lazily evaluated somewhat, whereas GetFiles
returns a string[]
which has to be fully populated before it can return.
这篇关于Directory.EnumerateFiles和Directory.GetFiles之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!