Difficulty: Easy
Correct Answer: Classes, Methods and Member-Variables
Explanation:
Introduction / Context:
When you create a custom attribute, you can restrict where it may be applied using the AttributeUsage attribute (AttributeTargets flags).
Given Data / Assumptions:
Concept / Approach:
Apply [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Field)] to limit where the custom attribute may appear. Thus it can be applied to classes, methods, and member variables (fields) if configured.
Step-by-Step Solution:
Verification / Alternative check:
Try applying to a disallowed target and observe the compiler’s diagnostic.
Why Other Options Are Wrong:
Options that mention only a subset are possible but the question asks whether it is possible to target multiple specific elements (including fields), which is true.
Common Pitfalls:
Forgetting that AttributeTargets is a flags enum and can be combined with bitwise OR.
Final Answer:
Classes, Methods and Member-Variables
Discussion & Comments