?
Solved

Difference betweem Find class and FindInfo class

Posted on 2013-11-14
3
Medium Priority
?
320 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 500 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 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

800 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