gpt4 book ai didi

c# - 为什么 File.Open 在覆盖现有文件方面比 File.Create 好得多?

转载 作者:太空狗 更新时间:2023-10-29 20:15:33 30 4
gpt4 key购买 nike

这与其他 SO question 有关询问如何覆盖现有文件。

最佳答案是这样的:

FileStream file = File.Open("text.txt", FileMode.Create);

我的回答是这样的:

FileStream fs = System.IO.File.Create(fileName);

在我写这个问题时,比分是 14-0,支持 Open

如果投票表示解决方案的优劣,这让我有点疑惑:

Is there something I'm missing in these methods that would make it clearly that much better to choose Open over Create?

最佳答案

对我来说,我确切地知道 File.Open("...", FileMode.Create) 做了什么,因为我可以将鼠标悬停在 FileMode.Create 上,它告诉我每次都会创建一个新文件。 File.Create("...") 没有指示它将执行此操作的工具提示。

关于c# - 为什么 File.Open 在覆盖现有文件方面比 File.Create 好得多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/793753/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com