Solved

Difference betweem Find class and FindInfo class

Posted on 2013-11-14
3
313 Views
Last Modified: 2013-11-14
I have a tutorial that used the FileInfo class to check if a file exists before creating a Streamwriter. Then, in the same course, it uses the simple file object to check if a file exists. I looked at both classes and they both seem to have the4 same methods and properties. So why or when would FileInfo be used instead of File?
0
Comment
Question by:BobHavertyComh
3 Comments
 
LVL 11

Assisted Solution

by:jasonduan
jasonduan earned 125 total points
ID: 39648684
When use File Class, you can call its static method Exists( ), in this case you don't have to create any object.
When use FileInfo Class, you have to create an FileInfo object, then check its property Exists
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 375 total points
ID: 39648730
The File class has static methods so you don't need to create an instance of it to use the methods, whereas a FileInfo class you have to create an instance of the class to use its methods.

Generally if you are performing a single operation on a file use the File class, if you're performing multiple operations on a file the use the FileInfo class. This is because of the security checking that is done when accessing a file. If you use the File class the security check is done every time you call a method of the File class. If you use the FleInfo class the security check is only done when you create the instance of the FileInfo class and therefore using FileInfo is more efficient when performing multiple operations on a file.
0
 
LVL 9

Author Closing Comment

by:BobHavertyComh
ID: 39648831
Both answers are correct, but Jack's answer was much more comprehensive and explained when one would use one of the other. Thanks guys.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question