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

File class static methods in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AReadAllText
BExists
CDelete
DCopy
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.
2fill in blank
medium

Complete 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'
AReadAllText
BWriteAllText
CAppendAllText
DDelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using WriteAllText tries to write, not read.
AppendAllText adds text instead of reading.
3fill in blank
hard

Fix 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'
ADelete
BMove
CCopy
DExists
Attempts:
3 left
💡 Hint
Common Mistakes
Using Delete removes the file instead of copying.
Using Move moves the file instead of copying.
4fill in blank
hard

Fill 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'
AWriteAllText
B"Hello, world!"
C"Sample text"
DAppendAllText
Attempts:
3 left
💡 Hint
Common Mistakes
Using AppendAllText adds text instead of overwriting.
Passing a variable name instead of a string literal.
5fill in blank
hard

Fill 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'
AExists
BMove
C"new.txt"
DCopy
Attempts:
3 left
💡 Hint
Common Mistakes
Using Copy instead of Move changes file behavior.
Not checking if file exists before moving.