Difficulty: Easy
Correct Answer: static void fun(object i) { ... }
Explanation:
Introduction / Context:
The question explores parameter typing strategies in C# when a method must accept values of different numeric types without duplicating logic.
Given Data / Assumptions:
Concept / Approach:
Using object as the parameter type allows any value type to be passed (boxed) or any reference type, enabling one method to accept both int and double. Alternative designs include method overloading (fun(int) and fun(double)), but only one choice here covers both in a single signature.
Step-by-Step Solution:
Verification / Alternative check:
Pattern matching: if (i is int ii) { ... } else if (i is double dd) { ... }
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting that overloading could also solve this but is not among the given valid single-signature options.
Final Answer:
static void fun(object i) { ... }
Discussion & Comments