0
0
C Sharp (C#)programming~5 mins

File class static methods in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the File.Exists method in C#?
The File.Exists method checks if a file exists at a specified path and returns true if it does, otherwise false.
Click to reveal answer
beginner
How does File.ReadAllText work?
It reads all the text from a file at a given path and returns it as a single string.
Click to reveal answer
beginner
What does File.WriteAllText do?
It creates a new file or overwrites an existing file with the specified text content.
Click to reveal answer
beginner
Explain the use of File.Delete.
The File.Delete method removes a file from the file system at the specified path if it exists.
Click to reveal answer
intermediate
What does File.Copy do and what important parameter does it have?
It copies a file from a source path to a destination path. It has an optional parameter to specify whether to overwrite the destination file if it already exists.
Click to reveal answer
Which File method reads all lines from a file into a string array?
AFile.ReadAllText
BFile.ReadAllLines
CFile.WriteAllText
DFile.Exists
What does File.Exists return if the file does not exist?
Athrows an exception
Btrue
Cnull
Dfalse
Which method would you use to overwrite a file with new text content?
AFile.WriteAllText
BFile.Delete
CFile.Copy
DFile.ReadAllText
What happens if you call File.Delete on a file that does not exist?
ADoes nothing
BThrows an exception
CCreates a new file
DReturns false
Which parameter in File.Copy controls overwriting the destination file?
Aappend (bool)
BbufferSize (int)
Coverwrite (bool)
Drecursive (bool)
Describe how you would check if a file exists and then read its entire content using File class static methods.
Think about checking first to avoid errors.
You got /3 concepts.
    Explain the difference between File.WriteAllText and File.AppendAllText.
    Consider what happens to existing file content.
    You got /3 concepts.