Directory.EnumerateFiles VS Directory.GetFiles之间的区别是什么? [英] What is the difference between Directory.EnumerateFiles vs Directory.GetFiles?

查看:191
本文介绍了Directory.EnumerateFiles VS Directory.GetFiles之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS 的GetFiles

显然,其中一个返回数组和其他返回枚举。

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 VS Directory.GetFiles之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆