为什么File.Exists()慢得多,当文件不存在? [英] Why is File.Exists() much slower when the file does not exist?

查看:603
本文介绍了为什么File.Exists()慢得多,当文件不存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,File.Exists()慢得多,当文件不存在,或使用不具有访问时,该文件确实存在比?这是没有道理给我。

Seems to me that File.Exists() is much slower when the file does not exist or the use doesn't have access than when the file does exist? This doesn't make sense to me.

推荐答案

通常,当你搜索了一堆东西的东西,你也不能肯定他们缺乏生存的,除非你搜索的所有可能的地方的也有可能是。当寻找的东西(在大多数种的集合)的最坏的情况是,当该项目不集合中存在

Generally when you search a bunch of stuff for something, you can't be sure about their lack of existence unless you have searched all possible places it could have been. When searching for something (in most kinds of collections) the worst case is when the item doesn't exist in the collection.

我没有基准 File.Exists 特别,但我高度怀疑,有一个在这些情况下,一个非常明显的区别,除非你正在做上千次。你是如何达到这个结论的?

I have not benchmarked File.Exists in particular but I highly doubt that there's a really noticeable difference in those cases unless you're doing it thousands of times. How did you reach to this conclusion?

这篇关于为什么File.Exists()慢得多,当文件不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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