C# - Structures Questions and Answers
C# Structures programming questions and answers help learners understand value types and memory management in .NET. Structures in C# are lightweight data types that store related data efficiently without the overhead of classes. Companies like Infosys, HCL, and TCS often include structure-related questions in interviews to test programming fundamentals. Practicing programming interview questions with answers based on structures allows candidates to learn syntax, constructors, field declarations, and performance differences compared to classes. Mastering structures improves understanding of memory optimization and efficient coding—vital skills for software developers and interview aspirants.
Study structures and unions in C programming. Pair this with data types and dynamic memory allocation
C# - Structures
31. What is boxing in relation to structures
- Converting structure to class
- Explanation: Boxing converts a value type into an object type.
- Converting object to value type
- Storing structure in array
32. What is unboxing in C#
- Explanation: Unboxing extracts the value type from an object.
- Destroying an object
- Copying structure value
- Casting class to structure
33. Which of the following can a structure not contain
- Fields
- Methods
- Explanation: Structures cannot contain destructors.
- Properties
34. What is the base type of all structures in C#
- Explanation: All structures implicitly inherit from System.ValueType.
- Object
- Struct
- BaseStruct
35. Which statement about mutable structures is correct
- They are immutable by default
- They cannot be modified
- Explanation: Structures are mutable unless fields are marked readonly.
- They are always constant
36. Which keyword makes a structure immutable
- sealed
- const
- Explanation: Using readonly fields helps make structures immutable.
- fixed
37. Which of the following is a valid use of a structure
- Database connection handling
- UI component creation
- Explanation: Structures are suitable for small data-centric types like points.
- Thread management
38. What happens if a structure is not initialized explicitly
- It causes runtime error
- It contains garbage values
- Explanation: Structure fields are automatically initialized to default values.
- It becomes null
39. Which statement about performance of structures is true
- Structures are slower than classes
- Explanation: Structures reduce heap allocation and garbage collection overhead.
- Structures always increase memory usage
- Structures are allocated only on heap