When talking about C # file operations, the instructor will talk about classes with similar functions, but their usage is different. They all exist in the systerm. Io namespace.
Both file and directory methods are static methods. Fileinfo and directoryinfo are both common methods. The instructor suggested that if you want to perform multiple Io operations on a file, you 'd better use two info classes. If you only perform one or two operations, you 'd better use a static method class.
I think it is for the following reasons and have been verified
Each time a static method operates on a file, the static method exists in the stack header. It is called by a class and then looks for the file to be operated. Search for operationsCompositionThe component process is an IO process, which takes a long time. However, it does not need to traverse new objects in the heap area.
A common method is called by an object at that time. You need to create a new object (this process is not required for a static method). However, if the number of operations is large, the general method does not need to execute unnecessary and time-consuming Io operations again, so the overall speed can be increased!
Therefore, the number of execution methods determines which class is the best choice.
Of course, I may ignore that file fileinfo is used to operate files, while directory directoryinfo is used to operate folders .....