vb.net banner

VB.NET Multiple Choice Questions (MCQs) and Answers

Master VB.NET with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Visual Basic.NET concepts. Begin your placement preparation journey now!

Q61

Q61 Identify the error in the following code:
Try Dim x As Integer = CInt("abc") Catch ex As FormatException Console.WriteLine("Invalid format") End Try

A

Invalid format

B

abc

C

0

D

Exception

Q62

Q62 What is the output of the following code?
Try Throw New Exception("Test Exception") Catch ex As Exception Console.WriteLine(ex.Message) End Try

A

Test Exception

B

Exception

C

Error

D

No Output

Q63

Q63 What happens if there is no Catch block for an exception in VB.NET?

A

The program crashes

B

The program continues

C

The program ignores the exception

D

The program stops execution gracefully

Q64

Q64 How can you identify the type of exception during debugging in VB.NET?

A

Check the exception message

B

Use a breakpoint

C

Hover over the exception object

D

Use the Watch window

Q65

Q65 While debugging, an exception is not being caught. What could be the reason?

A

The exception type is not specified in the Catch block

B

The exception occurs in a Finally block

C

The exception is not thrown

D

The exception is of type DivideByZeroException

Q66

Q66 Which namespace is used for file handling in VB.NET?

A

System.File

B

System.IO

C

System.Data

D

System.Text

Q67

Q67 Which class is used to create a new file in VB.NET?

A

FileCreate

B

FileMaker

C

FileStream

D

File

Q68

Q68 What is the purpose of the StreamReader class in VB.NET?

A

To write data to a file

B

To delete a file

C

To read characters from a file

D

To execute file operations

Q69

Q69 Which method of the File class is used to check if a file exists?

A

FileExists

B

CheckFile

C

Exists

D

IsFile

Q70

Q70 What is the purpose of the FileMode enumeration in VB.NET?

A

To set file access permissions

B

To specify how a file should be opened or created

C

To handle file exceptions

D

To manage file paths

Q71

Q71 What will the following code do?
Dim writer As New StreamWriter("test.txt") writer.WriteLine("Hello") writer.Close()

A

Create a file and write "Hello" to it

B

Delete a file

C

Throw an exception

D

Do nothing

Q72

Q72 How do you read all text from a file in VB.NET?

A

File.ReadAllText("file.txt")

B

StreamReader.ReadFile("file.txt")

C

File.ReadFile("file.txt")

D

File.GetText("file.txt")

Q73

Q73 What will the following code output?
If File.Exists("test.txt") Then Console.WriteLine("File exists") Else Console.WriteLine("File does not exist")

A

File exists

B

File does not exist

C

Error

D

No output

Q74

Q74 Identify the error in the following code:
Dim reader As New StreamReader("nonexistent.txt") Console.WriteLine(reader.ReadToEnd()) reader.Close()

A

File not found

B

Error opening file

C

Stream is null

D

No error

Q75

Q75 What happens if a file is locked by another process while being accessed in VB.NET?

A

Throws an IOException

B

Skips the file

C

Accesses the file

D

Deletes the file

Q76

Q76 How can you ensure a file stream is closed properly, even if an exception occurs?

A

Use Try-Catch

B

Use the Finally block

C

Use Using statement

D

Use File.Close() explicitly

Q77

Q77 A StreamWriter is writing data to a file but fails intermittently. What could be the issue?

A

File permissions are insufficient

B

File is read-only

C

Disk space is low

D

Buffer is not flushed

Q78

Q78 What is a collection in VB.NET?

A

A type of array

B

A class used to store and manage multiple items

C

A data type

D

A control

Q79

Q79 Which class in VB.NET is used for a dynamic array?

A

ArrayList

B

List

C

Dictionary

D

HashSet

Q80

Q80 What is the primary advantage of using generics in VB.NET?

A

Better performance

B

Type safety

C

Simplified code

D

Memory management

Q81

Q81 Which namespace provides classes for collections in VB.NET?

A

System.Collections

B

System.Collections.Generic

C

System.Collections.Concurrent

D

All of these

Q82

Q82 What is the difference between List and ArrayList in VB.NET?

A

List is fixed size

B

ArrayList is type-safe

C

List is generic and type-safe

D

ArrayList does not exist

Q83

Q83 Which of the following is the correct way to declare a generic List in VB.NET?

A

Dim numbers As New List(Of Integer)

B

Dim numbers As New ArrayList(Of Integer)

C

Dim numbers As List(Integer)

D

Dim numbers As New HashSet(Of Integer)

Q84

Q84 What will the following code output?
Dim names As New List(Of String) names.Add("Alice") names.Add("Bob") Console.WriteLine(names.Count)

A

1

B

2

C

0

D

Error

Q85

Q85 What is the correct way to iterate through a Dictionary in VB.NET?

A

For Each key As String In dict.Keys Console.WriteLine(key) Next

B

For i As Integer = 0 To dict.Count

C

For Each item As String In dict

D

None of these

Q86

Q86 What is the output of the following code?
Dim numbers As New HashSet(Of Integer) numbers.Add(1) numbers.Add(1) Console.WriteLine(numbers.Count)

A

1

B

2

C

Error

D

0

Q87

Q87 What happens if you try to add a duplicate key to a Dictionary in VB.NET?

A

Throws an ArgumentException

B

Replaces the existing key

C

Throws a runtime error

D

Allows duplicate keys

Q88

Q88 How can you handle a situation where a key is missing in a Dictionary?

A

Check using the ContainsKey method

B

Try-Catch block

C

Direct access

D

Using a default key

Q89

Q89 Why might a ConcurrentDictionary be used instead of a regular Dictionary?

A

To handle type mismatches

B

To handle concurrency issues in multithreaded environments

C

To add duplicate keys

D

To improve performance

Q90

Q90 What is ADO.NET primarily used for in VB.NET?

A

Reading and writing files

B

Accessing and managing databases

C

Handling exceptions

D

Creating user interfaces

ad verticalad vertical
ad