File and Fileinfo,directory and DirectoryInfo in C # and filesysteminfo__c#

Source: Internet
Author: User

In C # provides the file and the FileInfo class, these two classes of methods are basically the same, previously only know to use, has not figured out what is the difference, reading today a little unexpected harvest, and partners to share:

Both file and FileInfo provide action on files

The file class provides a static method, the file class cannot be inherited, nor does it produce an instance, and it is more efficient to use the file class than to use FileInfo, if it is only needed once or infrequently, but the file class spends time on the method for security checks. The FileInfo is only a check when the instance is produced, and will not be checked later, so if you need to repeatedly manipulate the file, using FileInfo will be more efficient than using file.

The same goes for the same directory as DirectoryInfo.

FileSystemInfo provides a common way for FileInfo and DirectoryInfo to operate on files or directories, and it is convenient to use FileSystemInfo when the object of the uncertainty operation is a file or directory.


The above is my understanding, if there is not the right place, please correct me and learn from each other.

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.