C#.NET generics — Which statement about generic procedures (generic methods) is valid?

Difficulty: Easy

Correct Answer: Only those procedures labeled as Generic are generic.

Explanation:


Introduction / Context:
Generic procedures (generic methods) are methods that declare their own type parameter list independent of whether the enclosing type is generic. This question checks the basic definition and scope of “generic” at the method level.



Given Data / Assumptions:

  • A class may be generic or non-generic.
  • Methods can be generic if they declare type parameters like after the method name.


Concept / Approach:
Only methods that explicitly declare type parameters are generic methods. Being defined inside a generic class does not automatically make every method generic; such methods can still be non-generic and simply use the class’s type parameters. Conversely, a non-generic class can contain a generic method.



Step-by-Step Solution:

Reject A: Enclosing generic class does not force all methods to be generic.Accept B: A method is generic only if it declares its own type parameter list.Reject C: Methods can have multiple type parameters, e.g., Dictionary.Create().Note on D: It is tautologically true by definition, but the exam emphasizes identification via the “labeled” type parameter list; B captures the practical rule.


Verification / Alternative check:
Write examples: a non-generic class with method M() compiles; a generic class with ordinary method N() is not a generic method.



Why Other Options Are Wrong:
They misstate scope (A), impose false limits (C), or rephrase the definition in a way that is less precise for identification (D).



Common Pitfalls:
Confusing “uses a generic type parameter from the class” with “is itself a generic method.”



Final Answer:
Only those procedures labeled as Generic are generic.

More Questions from Generics

Discussion & Comments

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