Solved

Difference betweem Find class and FindInfo class

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

17 Experts available now in Live!

Get 1:1 Help Now