C#.NET — Choose the correct method signature: receives (int, Single, double), returns decimal. Which definition is valid?

Difficulty: Easy

Correct Answer: static decimal fun(int i, Single j, double k) { ... }

Explanation:


Introduction / Context:
The question is about proper C# method declaration syntax: where the return type goes, whether static is allowed, and what parameter types look like. You must identify the one header that is syntactically correct for a method returning decimal and accepting (int, Single, double).


Given Data / Assumptions:

  • Return type must be decimal.
  • Parameters: int, Single (System.Single), double.
  • Method name: fun.


Concept / Approach:
In C#, the signature form is: [modifiers] return_type MethodName(parameter_list) { ... }. The return type precedes the method name. Either a static or an instance method is possible; using static is optional and valid here. Single is the CLR type for float and is allowed in a signature.


Step-by-Step Solution:

Option C: static decimal fun(int i, Single j, double k) { ... } — correct order and valid types. Option B: decimal fun(...) would also compile for an instance method, but the exam-style key typically expects the clearly correct header with an explicit modifier; among the choices, C is the unambiguously correct form. Options A/D: place decimal twice or in the wrong position. Option E: missing return type on the signature and uses "return decimal;" which is invalid.


Verification / Alternative check:
Compiling option C succeeds; changing Single to float also works because float is an alias of System.Single.


Why Other Options Are Wrong:
A/D/E violate signature syntax or return rules; B is acceptable as an instance method but is not the intended best answer against this key.


Common Pitfalls:
Placing the return type after the parameter list, or thinking Single is not allowed.


Final Answer:
static decimal fun(int i, Single j, double k) { ... }

More Questions from Functions and Subroutines

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion