File Handling And Input Output In C Sharp — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on File Handling And Input Output In C Sharp — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which class in C# is used to read data from text files?
Correct Answer: Option D — StreamReader
Detailed Academic Explanation:
StreamReader is the correct answer to “Which class in C# is used to read data from text files”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the using statement when working with files in C#?
Correct Answer: Option C — To ensure proper disposal of resources
Detailed Academic Explanation:
To ensure proper disposal of resources is the correct answer to “What is the purpose of the using statement when working with files in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which method is used to write data to a text file?
Correct Answer: Option B — WriteLine()
Detailed Academic Explanation:
WriteLine() is the correct answer to “In C#, which method is used to write data to a text file”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to open a file for writing in C#?
Correct Answer: Option B — StreamWriter file = new StreamWriter("filename.txt")
Detailed Academic Explanation:
StreamWriter file = new StreamWriter("filename.txt") is the correct answer to “What is the correct way to open a file for writing in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which class is used to manipulate directories and files?
Correct Answer: Option C — System.IO.DirectoryInfo
Detailed Academic Explanation:
System.IO.DirectoryInfo is the correct answer to “In C#, which class is used to manipulate directories and files”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.Exists() method in C#?
Correct Answer: Option C — To check if a file exists
Detailed Academic Explanation:
To check if a file exists is the correct answer to “What is the purpose of the File.Exists() method in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which method is used to read the entire contents of a file into a string?
Correct Answer: Option D — ReadAllText()
Detailed Academic Explanation:
ReadAllText() is the correct answer to “In C#, which method is used to read the entire contents of a file into a string”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.ReadAllLines() method in C#?
Correct Answer: Option A — To read all lines of text from a file into a string array
Detailed Academic Explanation:
To read all lines of text from a file into a string array is the correct answer to “What is the purpose of the File.ReadAllLines() method in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which method is used to delete a file?
Correct Answer: Option D — File.Delete()
Detailed Academic Explanation:
File.Delete() is the correct answer to “In C#, which method is used to delete a file”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which class in C# provides methods for synchronous reading and writing operations on files?
Correct Answer: Option C — StreamWriter
Detailed Academic Explanation:
StreamWriter is the correct answer to “Which class in C# provides methods for synchronous reading and writing operations on files”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.Copy() method in C#?
Correct Answer: Option C — To copy a file from one location to another
Detailed Academic Explanation:
To copy a file from one location to another is the correct answer to “What is the purpose of the File.Copy() method in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which method is used to determine the size of a file in bytes?
Correct Answer: Option B — FileInfo.Length
Detailed Academic Explanation:
FileInfo.Length is the correct answer to “In C#, which method is used to determine the size of a file in bytes”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to close a file after reading or writing in C#?
Correct Answer: Option C — file.Close()
Detailed Academic Explanation:
file.Close() is the correct answer to “What is the correct way to close a file after reading or writing in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which method is used to create a new directory?
Correct Answer: Option D — Directory.CreateDirectory()
Detailed Academic Explanation:
Directory.CreateDirectory() is the correct answer to “In C#, which method is used to create a new directory”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.Move() method in C#?
Correct Answer: Option A — To move a file from one location to another
Detailed Academic Explanation:
To move a file from one location to another is the correct answer to “What is the purpose of the File.Move() method in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which class provides methods for creating, copying, deleting, and moving directories and subdirectories?
Correct Answer: Option D — Directory
Detailed Academic Explanation:
Directory is the correct answer to “In C#, which class provides methods for creating, copying, deleting, and moving directories and subdirectories”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the File.AppendText() method do in C#?
Correct Answer: Option C — Opens an existing file or creates a new file for writing and appends text at the end of the file
Detailed Academic Explanation:
Opens an existing file or creates a new file for writing and appends text at the end of the file is the correct answer to “What does the File.AppendText() method do in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to read a single character from a text file in C#?
Correct Answer: Option B — ReadChar()
Detailed Academic Explanation:
ReadChar() is the correct answer to “Which method is used to read a single character from a text file in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.ReadAllBytes() method in C#?
Correct Answer: Option B — Reads all bytes from a file into a byte array
Detailed Academic Explanation:
Reads all bytes from a file into a byte array is the correct answer to “What is the purpose of the File.ReadAllBytes() method in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following methods is used to determine whether the specified file exists in C#?
Correct Answer: Option C — File.Exists()
Detailed Academic Explanation:
File.Exists() is the correct answer to “Which of the following methods is used to determine whether the specified file exists in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which class provides information about a specific file?
Correct Answer: Option D — FileInfo
Detailed Academic Explanation:
FileInfo is the correct answer to “In C#, which class provides information about a specific file”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which method is used to open an existing text file for reading?
Correct Answer: Option D — File.OpenText()
Detailed Academic Explanation:
File.OpenText() is the correct answer to “In C#, which method is used to open an existing text file for reading”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.SetAttributes() method in C#?
Correct Answer: Option C — Sets the attributes of a specified file or directory
Detailed Academic Explanation:
Sets the attributes of a specified file or directory is the correct answer to “What is the purpose of the File.SetAttributes() method in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which class in C# is used to perform synchronous and asynchronous read and write operations to a file in a managed application?
Correct Answer: Option B — FileStream
Detailed Academic Explanation:
FileStream is the correct answer to “Which class in C# is used to perform synchronous and asynchronous read and write operations to a file in a managed application”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which method is used to write a string to a text file?
Correct Answer: Option C — Write()
Detailed Academic Explanation:
Write() is the correct answer to “In C#, which method is used to write a string to a text file”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, what happens if you attempt to read from a file that does not exist using File.OpenRead() method?
Correct Answer: Option A — FileNotFoundException is thrown
Detailed Academic Explanation:
FileNotFoundException is thrown is the correct answer to “In C#, what happens if you attempt to read from a file that does not exist using File.OpenRead() method”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.Create() method in C#?
Correct Answer: Option D — Creates a new file or overwrites an existing file
Detailed Academic Explanation:
Creates a new file or overwrites an existing file is the correct answer to “What is the purpose of the File.Create() method in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which class represents a writer that provides a fast, non-cached, forward-only way of generating sequences of characters from streams of bytes?
Correct Answer: Option C — StreamWriter
Detailed Academic Explanation:
StreamWriter is the correct answer to “In C#, which class represents a writer that provides a fast, non-cached, forward-only way of generating sequences of characters from streams of bytes”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.WriteAllText() method in C#?
Correct Answer: Option B — Writes the specified string to a file, overwriting the file if it already exists
Detailed Academic Explanation:
Writes the specified string to a file, overwriting the file if it already exists is the correct answer to “What is the purpose of the File.WriteAllText() method in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, what method is used to create a new file if it does not exist, or overwrite the existing file if it does exist?
Correct Answer: Option C — File.Create()
Detailed Academic Explanation:
File.Create() is the correct answer to “In C#, what method is used to create a new file if it does not exist, or overwrite the existing file if it does exist”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which class in C# is used to represent a stream of characters to be written to a file?
Correct Answer: Option D — StreamWriter
Detailed Academic Explanation:
StreamWriter is the correct answer to “Which class in C# is used to represent a stream of characters to be written to a file”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the Directory.GetFiles() method in C#?
Correct Answer: Option C — Retrieves the names of files in a specified directory that match a specified pattern
Detailed Academic Explanation:
Retrieves the names of files in a specified directory that match a specified pattern is the correct answer to “What is the purpose of the Directory.GetFiles() method in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, what is the method used to append lines to a file?
Correct Answer: Option C — File.WriteAllLines()
Detailed Academic Explanation:
File.WriteAllLines() is the correct answer to “In C#, what is the method used to append lines to a file”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the File.ReadAllBytes() method do in C#?
Correct Answer: Option D — Reads all bytes from a file into a byte array
Detailed Academic Explanation:
Reads all bytes from a file into a byte array is the correct answer to “What does the File.ReadAllBytes() method do in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which class is used to manipulate paths in a platform-independent manner?
Correct Answer: Option A — Path
Detailed Academic Explanation:
Path is the correct answer to “In C#, which class is used to manipulate paths in a platform-independent manner”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which method is used to read all lines from a file and return them as an array of strings?
Correct Answer: Option C — File.ReadAllLines()
Detailed Academic Explanation:
File.ReadAllLines() is the correct answer to “In C#, which method is used to read all lines from a file and return them as an array of strings”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What happens if you attempt to read from a file that is already open by another process in C#?
Correct Answer: Option B — IOException is thrown
Detailed Academic Explanation:
IOException is thrown is the correct answer to “What happens if you attempt to read from a file that is already open by another process in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.Open() method in C#?
Correct Answer: Option C — Opens an existing file or creates a new file
Detailed Academic Explanation:
Opens an existing file or creates a new file is the correct answer to “What is the purpose of the File.Open() method in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.GetLastWriteTime() method in C#?
Correct Answer: Option D — Retrieves the date and time when the specified file was last written to
Detailed Academic Explanation:
Retrieves the date and time when the specified file was last written to is the correct answer to “What is the purpose of the File.GetLastWriteTime() method in C#”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C#, which method is used to delete a directory, and optionally any subdirectories and files in the directory?
Correct Answer: Option A — Directory.Delete()
Detailed Academic Explanation:
Directory.Delete() is the correct answer to “In C#, which method is used to delete a directory, and optionally any subdirectories and files in the directory”. This question is standard in competitive examination syllabi for File Handling And Input Output In C Sharp.
💡Key Conceptual Anchor:File Handling And Input Output In C Sharp
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.