C# - Structures Questions and Answers

Practice Mode
Showing 10 of 39 questions
Q31
What is boxing in relation to structures
  • A Converting structure to class
  • B Explanation: Boxing converts a value type into an object type.
  • C Converting object to value type
  • D Storing structure in array
Answer: Option B
Explanation: Boxing converts a value type into an object type.
Q32
What is unboxing in C#
  • A Explanation: Unboxing extracts the value type from an object.
  • B Destroying an object
  • C Copying structure value
  • D Casting class to structure
Answer: Option A
Explanation: Unboxing extracts the value type from an object.
Q33
Which of the following can a structure not contain
  • A Fields
  • B Methods
  • C Explanation: Structures cannot contain destructors.
  • D Properties
Answer: Option C
Explanation: Structures cannot contain destructors.
Q34
What is the base type of all structures in C#
  • A Explanation: All structures implicitly inherit from System.ValueType.
  • B Object
  • C Struct
  • D BaseStruct
Answer: Option A
Explanation: All structures implicitly inherit from System.ValueType.
Q35
Which statement about mutable structures is correct
  • A They are immutable by default
  • B They cannot be modified
  • C Explanation: Structures are mutable unless fields are marked readonly.
  • D They are always constant
Answer: Option C
Explanation: Structures are mutable unless fields are marked readonly.
Q36
Which keyword makes a structure immutable
  • A sealed
  • B const
  • C Explanation: Using readonly fields helps make structures immutable.
  • D fixed
Answer: Option C
Explanation: Using readonly fields helps make structures immutable.
Q37
Which of the following is a valid use of a structure
  • A Database connection handling
  • B UI component creation
  • C Explanation: Structures are suitable for small data-centric types like points.
  • D Thread management
Answer: Option C
Explanation: Structures are suitable for small data-centric types like points.
Q38
What happens if a structure is not initialized explicitly
  • A It causes runtime error
  • B It contains garbage values
  • C Explanation: Structure fields are automatically initialized to default values.
  • D It becomes null
Answer: Option C
Explanation: Structure fields are automatically initialized to default values.
Q39
Which statement about performance of structures is true
  • A Structures are slower than classes
  • B Explanation: Structures reduce heap allocation and garbage collection overhead.
  • C Structures always increase memory usage
  • D Structures are allocated only on heap
Answer: Option B
Explanation: Structures reduce heap allocation and garbage collection overhead.
Questions and Answers for Competitive Exams Various Entrance Test