Solved

Difference betweem Find class and FindInfo class

Posted on 2013-11-14
3
310 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sum Column in GridView 3 41
Asp.net mvc foreach 3 32
Error in page 3 44
WCF Service Application cannot connect from TCP terminal 1 9
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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now