Difficulty: Easy
Correct Answer: Emp e = new Emp();
Explanation:
Introduction / Context:
This question asks for a correct declaration/initialization pattern for a user-defined struct Emp. For parameterless construction of a struct, C# permits using new Emp() to create a zero-initialized instance, invoking the implicit parameterless initializer logic for value types (unless an explicit parameterized constructor is defined).
Given Data / Assumptions:
Concept / Approach:
For value types, you can either declare a variable and then assign with new Emp(), or perform both in one statement. The keyword new zero-initializes all fields. Syntax must include parentheses when calling the parameterless initializer for a struct. The distractors either omit parentheses, reverse assignment, or use signatures that do not compile in C#.
Step-by-Step Solution:
Verification / Alternative check:
If desired, the two-line valid equivalent is: Emp e; e = new Emp(); which also compiles and creates a zero-initialized struct instance.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting parentheses when using new with structs; confusing C# syntax with C/C++ forms; misreading “Emp e();” as a variable instead of a method-like form.
Final Answer:
Emp e = new Emp();
Discussion & Comments