Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a file exists at the given path.
C Sharp (C#)
bool exists = File.[1]("example.txt");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ReadAllText instead of Exists causes runtime error if file missing.
Using Delete or Copy does not check existence.
✗ Incorrect
The File.Exists method checks if the specified file exists and returns a boolean.
2fill in blank
mediumComplete the code to read all text from a file into a string.
C Sharp (C#)
string content = File.[1]("data.txt");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WriteAllText tries to write, not read.
AppendAllText adds text instead of reading.
✗ Incorrect
File.ReadAllText reads the entire content of a text file into a string.
3fill in blank
hardFix the error in the code to copy a file from source to destination.
C Sharp (C#)
File.[1]("source.txt", "dest.txt");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Delete removes the file instead of copying.
Using Move moves the file instead of copying.
✗ Incorrect
File.Copy copies a file from one path to another.
4fill in blank
hardFill both blanks to write text to a file, overwriting if it exists.
C Sharp (C#)
File.[1]("log.txt", [2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using AppendAllText adds text instead of overwriting.
Passing a variable name instead of a string literal.
✗ Incorrect
File.WriteAllText writes the given string to the file, replacing existing content.
5fill in blank
hardFill all three blanks to move a file only if it exists.
C Sharp (C#)
if (File.[1]("old.txt")) { File.[2]("old.txt", [3]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Copy instead of Move changes file behavior.
Not checking if file exists before moving.
✗ Incorrect
First, File.Exists checks if the file is there. Then File.Move moves it to the new path "new.txt".