Difficulty: Easy
Correct Answer: 1, 2, 5
Explanation:
Introduction / Context:
This question checks your knowledge of implicit and explicit numeric conversions in C#, especially narrowing versus widening conversions and how literals are treated.
Given Data / Assumptions:
Concept / Approach:
Rule of thumb: If the target type can represent all values of the source type, the conversion may be implicit (widening). Otherwise, an explicit cast is needed (narrowing). The compiler also performs constant-expression checks for literals.
Step-by-Step Solution:
Verification / Alternative check:
Compile small snippets demonstrating byte b = 3.14f; (error) vs float f = (byte)200; (works with cast) vs float f2 = (byte)10; (implicit allowed as widening).
Why Other Options Are Wrong:
Any set including (3) or (4) is incorrect due to misunderstanding widening rules and char conversions.
Common Pitfalls:
Assuming all numeric types interconvert implicitly; ignoring constant-expression range checks for literals.
Final Answer:
1, 2, 5
Discussion & Comments