I\'ve been reading that the static methods of the File
Class are better used to perform small and few tasks on a file like checking to see if it exists and that
The major difference between File
class and FileInfo
class is that
Both members of the
File
andFileInfo
class are decorated with the[System.Security.SecurityCritical] and [System.Security.SecuritySafeCritical]
attribute butFile
class has 'multiple security checks' as compared toFileInfo
class (Read Here) and the check is performed each time when you call a static member of theFile
class.When you create an instance of
FileInfo
, the check is performed only once.
File
is a static type class whereas FileInfo
is an instance type class.FileInfo
class you need to create an instance whereas in File
class you can directly access its members without the need to create an instance.FileInfo
instance methods instead of the corresponding static methods of the File
class.File
class provides more methods as compared to FileInfo
class.Note: Either the SecurityCriticalAttribute attribute or the SecuritySafeCriticalAttribute attribute must be applied to code for the code to perform security-critical operations.