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

You apply a custom attribute and read it back. Why might calling GetCustomAttribute twice return two different object instances?

[AttributeUsage(AttributeTargets.Class)] class TagAttribute : Attribute { } [Tag] class Foo { } var a = typeof(Foo).GetCustomAttribute<TagAttribute>(); var b = typeof(Foo).GetCustomAttribute<TagAttribute>(); Console.WriteLine(ReferenceEquals(a, b));