MCQs on VB.NET Syntax and Basics | Visual Basic .NET (VB.NET)

Test your understanding of VB.NET’s foundational concepts! This quiz covers variables, data types, constants, operators, expressions, and type conversions. Perfect for learners looking to enhance their VB.NET skills.


Variables and Data Types

  1. Which keyword is used to declare a variable in VB.NET?
    a) Dim
    b) Var
    c) Declare
    d) Set
  2. What data type is used for storing a single Unicode character in VB.NET?
    a) String
    b) Char
    c) Byte
    d) Integer
  3. Which of the following is a value type in VB.NET?
    a) String
    b) Integer
    c) Array
    d) Object
  4. What is the default value of an uninitialized Boolean variable in VB.NET?
    a) True
    b) False
    c) Null
    d) 0
  5. How do you declare a variable with a specific data type in VB.NET?
    a) Var variableName As DataType
    b) Dim variableName As DataType
    c) Declare variableName DataType
    d) Set variableName DataType

Constants and Enumerations

  1. How do you declare a constant in VB.NET?
    a) Static
    b) Const
    c) Final
    d) Immutable
  2. Which keyword is used to define an enumeration in VB.NET?
    a) Enum
    b) Enumeration
    c) List
    d) Type
  3. Can an enumeration in VB.NET contain values of different data types?
    a) Yes
    b) No
  4. What is the default starting value for an enumeration in VB.NET if not specified?
    a) 1
    b) 0
    c) -1
    d) Null
  5. What is a correct example of declaring an enumeration in VB.NET?
    a) Enum Colors {Red, Blue, Green}
    b) Enum Colors As Byte {Red, Blue, Green}
    c) Enum Colors: Red, Blue, Green
    d) Enum Colors = (Red, Blue, Green)

Basic Operators and Expressions

  1. What operator is used for concatenating strings in VB.NET?
    a) +
    b) &
    c) ||
    d) .
  2. Which operator checks for equality in VB.NET?
    a) ==
    b) Equals
    c) =
    d) ===
  3. What does the Mod operator in VB.NET do?
    a) Exponentiation
    b) Division
    c) Remainder
    d) Multiplication
  4. Which operator is used for logical AND in VB.NET?
    a) &&
    b) AND
    c) &
    d) ANDAlso
  5. What will the expression “5 ^ 3” return in VB.NET?
    a) 125
    b) 15
    c) 2
    d) 8

Type Casting and Conversions

  1. Which method converts a string to an integer in VB.NET?
    a) CInt()
    b) Convert.ToInt()
    c) ToInt()
    d) Parse.Int()
  2. What is the difference between CType() and DirectCast()?
    a) CType is faster than DirectCast.
    b) DirectCast performs runtime checks; CType does not.
    c) CType allows conversions; DirectCast requires exact types.
    d) There is no difference.
  3. What happens if you try to cast an incompatible type using CType()?
    a) Returns null
    b) Throws an InvalidCastException
    c) Converts to the closest type
    d) Generates a warning
  4. Which keyword is used for implicit type casting in VB.NET?
    a) AutoCast
    b) Widening
    c) Implicit
    d) Explicit
  5. Which of these methods converts a value to a string in VB.NET?
    a) CStr()
    b) Convert.ToString()
    c) ToString()
    d) All of the above

Mixed Concepts

  1. Which of these is a reference type in VB.NET?
    a) Integer
    b) String
    c) Boolean
    d) Char
  2. Can VB.NET variables hold null values by default?
    a) Yes, all variables can hold null.
    b) Only reference types can hold null.
    c) No, null values are not supported.
    d) Only string variables can hold null.
  3. What is the scope of a variable declared with the “Static” keyword in a procedure?
    a) Class-level scope
    b) Global scope
    c) Procedure-level scope
    d) File-level scope
  4. What will the result of “10 / 3” return in VB.NET for Integer types?
    a) 3
    b) 3.333
    c) 0
    d) Error
  5. Which method ensures type safety during conversions in VB.NET?
    a) CType()
    b) DirectCast()
    c) TryCast()
    d) Convert()
  6. What happens when an undeclared variable is used in VB.NET?
    a) Throws a compile-time error
    b) Creates a dynamic variable
    c) Initializes it to null
    d) Initializes it to 0
  7. How do you check if a variable is of a specific type?
    a) IsType()
    b) TypeOf…Is
    c) CheckType()
    d) GetType().Equals
  8. Can VB.NET handle conversions between incompatible data types?
    a) Yes, automatically
    b) No, it throws an exception
    c) Only using CType()
    d) Only for string data types
  9. What is the data type for a VB.NET variable that can hold any type of data?
    a) Variant
    b) Object
    c) Dynamic
    d) Any
  10. Which statement allows you to initialize multiple variables in VB.NET?
    a) Dim a, b, c As Integer
    b) Var a = 1, b = 2, c = 3
    c) Int a = 1; b = 2; c = 3
    d) Set a = 1, b = 2, c = 3

Answer Key

QnoAnswer (Option with the Text)
1a) Dim
2b) Char
3b) Integer
4b) False
5b) Dim variableName As DataType
6b) Const
7a) Enum
8b) No
9b) 0
10a) Enum Colors {Red, Blue, Green}
11b) &
12c) =
13c) Remainder
14b) AND
15a) 125
16a) CInt()
17c) CType allows conversions; DirectCast requires exact types
18b) Throws an InvalidCastException
19b) Widening
20d) All of the above
21b) String
22b) Only reference types can hold null
23c) Procedure-level scope
24a) 3
25c) TryCast()
26a) Throws a compile-time error
27b) TypeOf…Is
28b) No, it throws an exception
29b) Object
30a) Dim a, b, c As Integer

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