Test your knowledge of VB.NET Collections and Generics with these expertly crafted MCQs. Explore Arrays, ArrayLists, Dictionaries, HashTables, and Generics to master intermediate-level programming concepts effectively.
Topic: Arrays and ArrayList
Which of the following correctly declares an array in VB.NET? a) Dim arr(5) As String b) Dim arr As String[5] c) Dim arr{} As String d) Dim arr(5)
What is the default index of the first element in a VB.NET array? a) 0 b) 1 c) -1 d) Undefined
What is the difference between an Array and an ArrayList in VB.NET? a) Array is dynamic; ArrayList is fixed-size b) ArrayList is dynamic; Array is fixed-size c) Both are dynamic d) Both are fixed-size
How do you add an item to an ArrayList in VB.NET? a) AddItem() b) Add() c) Insert() d) Append()
Which property of the ArrayList class gets the number of elements? a) Length b) Count c) Size d) Items
Which method clears all elements of an ArrayList? a) ClearItems() b) Clear() c) Reset() d) RemoveAll()
In VB.NET, what happens if you try to access an array index out of bounds? a) The array is resized b) A runtime exception occurs c) The program terminates d) It returns a default value
How can you create a multidimensional array in VB.NET? a) Dim arr(2,3) As Integer b) Dim arr[2][3] As Integer c) Dim arr(3,2) d) Dim arr(3)(2) As Integer
Topic: Dictionaries and HashTables
What is the primary difference between a Dictionary and a HashTable in VB.NET? a) Dictionary uses type-safe keys and values; HashTable does not b) HashTable is faster than Dictionary c) Dictionary allows duplicate keys; HashTable does not d) HashTable does not support keys
Which method is used to add a key-value pair to a Dictionary in VB.NET? a) Append() b) Add() c) Insert() d) AddKey()
In a HashTable, what happens if a duplicate key is added? a) It overwrites the existing value b) It throws an exception c) It is ignored d) It creates a new key
How can you check if a specific key exists in a Dictionary? a) ContainsKey() b) KeyExists() c) FindKey() d) HasKey()
What does the GetEnumerator() method in a Dictionary return? a) A list of keys b) A list of values c) A Dictionary enumerator d) Key-value pairs
Which namespace is required for using Dictionary and HashTable in VB.NET? a) System.IO b) System.Collections.Generic c) System.Linq d) System.Net
How do you remove an entry from a HashTable? a) RemoveKey() b) Delete() c) Remove() d) ClearKey()
In VB.NET, what does the Keys property of a Dictionary return? a) A list of all keys b) A list of all values c) A Boolean indicating if keys exist d) Null
Topic: Introduction to Generics (List, Dictionary)
What is the primary advantage of generics in VB.NET? a) Reduced memory usage b) Increased performance c) Type safety and flexibility d) Simplified syntax
How do you declare a generic List in VB.NET? a) Dim list As New List(Of T) b) Dim list As New List<T> c) Dim list As List(Of T) d) Dim list = New List(T)
Which method is used to add an item to a generic List? a) Append() b) Add() c) Insert() d) Push()
Can a generic Dictionary have duplicate keys in VB.NET? a) Yes b) No
What does the ContainsValue() method in a generic Dictionary do? a) Checks if a key exists b) Checks if a value exists c) Finds the key of a value d) Clears the dictionary
How do you specify the type of a generic Dictionary? a) Dim dict As New Dictionary(Key, Value) b) Dim dict As New Dictionary(Of KeyType, ValueType) c) Dim dict As Dictionary<Key, Value> d) Dim dict As Dictionary(Of Key, Value)
Which method removes an item from a generic List in VB.NET? a) RemoveAt() b) Delete() c) Clear() d) Remove()
What is the default value for a generic type parameter in VB.NET? a) Null b) Zero c) The type’s default value d) Undefined
Can generics be used with custom types in VB.NET? a) Yes b) No
Which keyword is used to define a generic class in VB.NET? a) Generic b) Of c) Template d) ClassType
What is the difference between a List and a generic Dictionary? a) List is key-value based; Dictionary is index-based b) Dictionary is key-value based; List is index-based c) Both are key-value based d) Both are index-based
How do you sort a generic List in VB.NET? a) Sort() method b) Order() method c) Arrange() method d) Reorder() method
Can a generic method have multiple type parameters? a) Yes b) No
What is the correct way to declare a generic method in VB.NET? a) Sub Method(Of T)() b) Sub Method<T>() c) Sub Method<T, U>() d) Sub Method(T)()
Answers
QNo
Answer
1
a) Dim arr(5) As String
2
a) 0
3
b) ArrayList is dynamic; Array is fixed-size
4
b) Add()
5
b) Count
6
b) Clear()
7
b) A runtime exception occurs
8
a) Dim arr(2,3) As Integer
9
a) Dictionary uses type-safe keys and values; HashTable does not
10
b) Add()
11
b) It throws an exception
12
a) ContainsKey()
13
d) Key-value pairs
14
b) System.Collections.Generic
15
c) Remove()
16
a) A list of all keys
17
c) Type safety and flexibility
18
a) Dim list As New List(Of T)
19
b) Add()
20
b) No
21
b) Checks if a value exists
22
b) Dim dict As New Dictionary(Of KeyType, ValueType)
23
a) RemoveAt()
24
c) The type’s default value
25
a) Yes
26
b) Of
27
b) Dictionary is key-value based; List is index-based