Solved

Difference betweem Find class and FindInfo class

Posted on 2013-11-14
3
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Amazon S3 .Net error 5 43
C# Linq Select From List 3 47
Dictionary and array of [N] size - performance tuned 12 41
ASP.NET data base connection 35 42
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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