Differences between file and directory, fileinfo and directoryinfo

Source: Internet
Author: User

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 .....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.