Skip to content

Attributes

Question

Explain attributes. What data can be passed into them, and where is that information stored?

Short interview answer

Attributes attach declarative metadata to assemblies and program elements. Constructor arguments and named public fields or properties use a restricted set of compile-time metadata values. The metadata is stored in the assembly and can be read through reflection.

Detailed answer

Attributes commonly express serialization, interop, test, or framework behavior. An attribute declaration is metadata, not automatically executed behavior; a compiler, runtime, or framework must read and act on it. Allowed argument values are limited by the language specification, including primitive values, strings, Type, enums, and arrays of allowed types.

Sources