Skip to content

Value Types and Interfaces

Question

Can a value type implement an interface?

Short interview answer

Yes. A struct can implement one or more interfaces, even though it cannot inherit from a class or another struct.

Detailed answer

For example, a value type can implement IComparable<T> or IFormattable. Be aware that assigning a struct to a non-generic interface or object can box it, which may matter in performance-sensitive code.

Sources