什么是My.Computer.FileSystem和System.IO.File之间的区别 [英] What exactly is the difference between My.Computer.FileSystem and System.IO.File
问题描述
My.Computer.FileSystem
和 System.IO.File
中有很多重复的功能,命名空间。
There is a lot of duplication of functions in the My.Computer.FileSystem
and System.IO.File
namespaces.
这是什么是区别:
My.Computer.FileSystem.CopyFile(source, dest, True)
和:
System.IO.File.Copy(source, dest, True)
有性能差异吗?每个人对可读性有什么优势?我个人使用 My.Computer
命名空间,但这只是习惯。
Is there a performance difference? What is everyone's opinion on which which has the edge on read-ability? I personally use the My.Computer
Namespace but that is just habit now.
推荐答案
My。*仅仅是一组为VB.NET实现的立面模式类,包含常见的System.IO *(和其他)操作。有一个非常的性能影响很小,因为你要经历一个额外的抽象层,但你必须决定是否值得优化。我建议您使用对您和您商店中其他人有意义的方式。
My.* is simply a set of facade-pattern classes implemented for VB.NET that encompass common System.IO* (and other) operations. There is a very tiny performance hit since you're going through an extra layer of abstraction but you have to decide if it's worth optimizing for that. I would suggest using whichever way makes sense to you and others in your shop.
如果您检查 My.Computer.FileSystem.CopyFile
与.NET反射器,你会看到该方法包装许多System.IO类,如文件和目录,特别是文件类'复制,移动和删除方法。 Snippet:
If you examine the code for My.Computer.FileSystem.CopyFile
with .NET Reflector you will see that the method wraps many System.IO classes such as File and Directory and especially the File class' Copy, Move and Delete methods. Snippet:
'lots of other code snipped out for brevity and to show the use of System.IO classes...
Directory.CreateDirectory(FileSystem.GetParentPath(str))
'snip
If
' snip
Else
File.Delete(str)
File.Move(path, str)
End If
Else
File.Move(path, str)
End If
End Sub
这篇关于什么是My.Computer.FileSystem和System.IO.File之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!