MCQs on Basic Input/Output | Visual Basic .NET (VB.NET)

Explore these 30 engaging MCQs to test your knowledge of Basic Input/Output in VB.NET. Covering Console usage, file handling, and output formatting, this quiz helps strengthen your programming basics!


Using the Console

  1. Which method is used to read input from the user in VB.NET?
    • A. Console.Read
    • B. Console.ReadLine
    • C. Console.Write
    • D. Console.WriteLine
  2. What does Console.WriteLine do in VB.NET?
    • A. Writes output without a newline
    • B. Writes output with a newline
    • C. Reads input with a newline
    • D. Clears the console
  3. Which method is used to clear the console screen?
    • A. Console.Reset
    • B. Console.Clean
    • C. Console.Clear
    • D. Console.Flush
  4. What happens if you call Console.ReadLine but no input is provided?
    • A. Throws an exception
    • B. Returns null
    • C. Returns an empty string
    • D. Returns a newline
  5. How can you format output directly in a Console.WriteLine statement?
    • A. Using escape sequences
    • B. Using placeholders {}
    • C. Using interpolation $
    • D. Both B and C

Basic File I/O (Read/Write)

  1. Which class is used to write text to a file in VB.NET?
    • A. FileStream
    • B. StreamWriter
    • C. TextWriter
    • D. FileWriter
  2. What does the File.Create method do?
    • A. Creates and opens a file
    • B. Appends data to a file
    • C. Deletes a file
    • D. Reads a file
  3. Which method reads all lines from a text file?
    • A. File.ReadText
    • B. File.ReadLines
    • C. File.ReadAllText
    • D. File.ReadAllLines
  4. How do you append data to an existing file?
    • A. File.WriteText
    • B. File.AppendText
    • C. File.AddLine
    • D. File.Create
  5. What happens if you write to a file that doesn’t exist?
  • A. Throws an error
  • B. Creates a new file
  • C. Skips the operation
  • D. Appends data
  1. Which namespace is primarily used for file operations in VB.NET?
  • A. System.IO
  • B. System.Text
  • C. System.Data
  • D. System.File
  1. What is the purpose of the StreamReader class?
  • A. Reading binary files
  • B. Reading text from a stream
  • C. Writing to a stream
  • D. Managing file paths
  1. How do you close a StreamWriter after use?
  • A. StreamWriter.Close
  • B. StreamWriter.Dispose
  • C. StreamWriter.Flush
  • D. Both A and B
  1. What happens if a file is locked when trying to write using StreamWriter?
  • A. Overwrites the file
  • B. Skips the write operation
  • C. Throws an exception
  • D. Opens in read mode
  1. Which class is used to delete files?
  • A. FileStream
  • B. File.Delete
  • C. FileManager
  • D. FileWriter

Formatting Output

  1. How do you format a floating-point number to two decimal places in VB.NET?
  • A. F2
  • B. .ToString("F2")
  • C. Format(2)
  • D. Round(2)
  1. Which method is used to align output in columns?
  • A. String.Format
  • B. TabAlign
  • C. PadLeft/PadRight
  • D. Console.Align
  1. What is the purpose of the String.Format method?
  • A. Concatenates strings
  • B. Formats strings
  • C. Trims strings
  • D. Pads strings
  1. How do you represent a percentage in formatted output?
  • A. .ToString("%")
  • B. .ToString("P")
  • C. .Format("%")
  • D. .ToString("F%")
  1. Which escape sequence is used for a newline in VB.NET?
  • A. \n
  • B. \r
  • C. \t
  • D. \l
  1. How do you display a currency symbol using formatting?
  • A. .ToString("C")
  • B. .Format("Currency")
  • C. "$" + Value
  • D. .ToCurrency()
  1. What happens when Console.WriteLine uses {0} as a placeholder?
  • A. Throws an error
  • B. Formats the string
  • C. Outputs a default value
  • D. Inserts the first argument
  1. How do you include a tab in a formatted string?
  • A. "\t"
  • B. "Tab"
  • C. "\b"
  • D. "Space(4)"
  1. What is the output of .ToString("D4") for the value 5?
  • A. 0005
  • B. 005
  • C. 5.000
  • D. D0005
  1. How can you ensure formatted alignment for a table-like display?
  • A. String.PadLeft/String.PadRight
  • B. String.Trim
  • C. Console.AlignTab
  • D. Console.RowFormat
  1. Which symbol is used for custom numeric format patterns?
  • A. $
  • B. #
  • C. *
  • D. &
  1. What does the "E" format specifier represent?
  • A. Exponential notation
  • B. Empty string
  • C. Exact decimal
  • D. Error
  1. Which property of strings is commonly used for trimming output?
  • A. .Trim()
  • B. .Cut()
  • C. .Remove()
  • D. .Clean()
  1. How do you display negative numbers in parentheses?
  • A. ("C")
  • B. .ToString("(#)")
  • C. .ToString("N0")
  • D. .ToString("#,##0.00;(#,##0.00)")
  1. How do you round numbers to the nearest integer in VB.NET?
  • A. .Round()
  • B. .ToInteger()
  • C. .ToString("F0")
  • D. .RoundInt()

Answer Key

QnoAnswer (Option with the text)
1B. Console.ReadLine
2B. Writes output with a newline
3C. Console.Clear
4C. Returns an empty string
5D. Both B and C
6B. StreamWriter
7A. Creates and opens a file
8D. File.ReadAllLines
9B. File.AppendText
10B. Creates a new file
11A. System.IO
12B. Reading text from a stream
13D. Both A and B
14C. Throws an exception
15B. File.Delete
16B. .ToString(“F2”)
17C. PadLeft/PadRight
18B. Formats strings
19B. .ToString(“P”)
20A. \n
21A. .ToString(“C”)
22D. Inserts the first argument
23A. \t
24A. 0005
25A. String.PadLeft/String.PadRight
26B. #
27A. Exponential notation
28A. .Trim()
29D. .ToString(“#,##0.00;(#,##0.00)”)
30A. .Round()

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top