File and fileInfo:
The File class is a static class. Because all File methods are static, if you only want to perform one operation, the efficiency of using the File method is higher than that of using the corresponding FileInfo instance method. All File methods require the path of the File currently operated. The static method of the File class performs security checks on all methods. If you want to reuse an object multiple times, you can use the corresponding FileInfo instance method because security check is not always required.
File, directory, FileInfo, DirectoryInfo
File, directory can control multiple files so that each security check is performed, while FileInfo and DirectoryInfo can only control one file for only one security process.
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. The process of searching for files to be operated 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.