Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumC#reflection and attributesSingle-choice MCQ

Why does calling `GetCustomAttribute` here return null even though the attribute is clearly applied?

[AttributeUsage(AttributeTargets.Class, Inherited = false)] class TagAttribute : Attribute { } [Tag] class Base { } class Derived : Base { } var a = typeof(Derived).GetCustomAttribute<TagAttribute>(); Console.WriteLine(a == null); // prints what?