C#.NET — Defaults, variable-argument methods, and error types in definitions. Which statements are correct? C# allows a function to have arguments with default values. C# allows a function to have a variable number of arguments. Omitting the return value type in a method definition results in an exception. Redefining a method parameter inside the method body causes an exception. The params keyword specifies a variable number of arguments.
-
A1, 3, 5
-
B3, 4, 5
-
C2, 5
-
D4, 5
-
ENone of these
Answer
Correct Answer: None of these
Explanation
Introduction / Context:This question mixes method defaults, variable argument lists, and the distinction between compile-time errors and runtime exceptions in C# method declarations and bodies.
Given Data / Assumptions:
- Five statements discuss defaults, params, and error types.
- We must identify which combination is correct.
Concept / Approach:In C#, default parameter values are supported. Variable-length argument lists are supported using the params keyword (and such an argument must be last). Omitting a return type or attempting to redeclare a parameter name inside the method does not cause a runtime exception; instead, these are compile-time errors. Therefore, statements 1, 2, and 5 are accurate, while 3 and 4 are inaccurate as phrased (they misuse “exception”). No option lists exactly 1, 2, and 5 together, so “None of these” is the only correct choice.
Step-by-Step Solution:
1) True — default values (e.g., void X(int a = 5)) are allowed. 2) True — variable arguments via params. 3) False — missing return type is a compile-time error, not a runtime exception. 4) False — redefining a parameter name would be a compile-time error; no exception at runtime. 5) True — params specifies the syntax for a variable number of arguments and must be the last parameter.Verification / Alternative check:Attempt to compile samples: removing a return type fails at compile time; re-declaring a local that conflicts with a parameter name fails likewise; defaults and params compile and behave as expected.
Why Other Options Are Wrong:
- A includes 3 (false).
- B includes 3 and 4 (both false).
- C includes 2 and 5 but omits 1 (true).
- D includes 4 (false).
Common Pitfalls:Mixing up exceptions (runtime) with compiler diagnostics; forgetting that params must be the last parameter.
Final Answer:None of these