Difficulty: Easy
Correct Answer: Attributes are recorded into assembly metadata; they can be read via reflection; attributes can take parameters
Explanation:
Introduction / Context:
Attributes provide declarative metadata in .NET. Understanding their lifecycle—from source code to compiled assembly to runtime inspection—is important for using frameworks and tooling effectively.
Given Data / Assumptions:
Concept / Approach:
When a C# program is compiled, attributes are emitted as metadata in the resulting assembly (DLL/EXE). At runtime (and design-time), reflection APIs can read those attributes. Attributes support positional constructor arguments and named property/field assignments.
Step-by-Step Solution:
Verification / Alternative check:
Create a custom attribute with a constructor and a named property; apply it; then use reflection to retrieve and read both the positional and named values at runtime.
Why Other Options Are Wrong:
Options asserting deletion or non-reflectability misunderstand the metadata model; attributes are not “thrown away.”
Common Pitfalls:
Confusing attribute constructor parameters with named property initializers; forgetting that attributes are read-only at runtime in terms of behavior—they annotate, they don’t execute themselves.
Final Answer:
Attributes are recorded into assembly metadata; they can be read via reflection; attributes can take parameters
Discussion & Comments