Complete the code to apply a simple attribute named MyAttribute.
[[1]] public class MyClass {}
The correct syntax to apply an attribute uses the attribute name inside square brackets. The class name conventionally ends with Attribute, but the suffix is omitted when applying the attribute.
Complete the code to declare a custom attribute class named SampleAttribute.
public class [1] : System.Attribute {}
System.Attribute.Custom attributes must inherit from System.Attribute. The class name conventionally ends with 'Attribute'.
Fix the error in the attribute usage syntax.
[Obsolete[1]]
public void OldMethod() {}When using an attribute with parameters, parentheses () are required even if no parameters are passed.
Fill both blanks to declare an attribute with a positional parameter.
public class [1] : System.Attribute { public [2](string name) {} }
The class name should be AuthorAttribute and the constructor name should be Author to allow usage as [Author("name")].
Fill all three blanks to declare and use a named parameter in an attribute.
[[1](Version = [2])] public class MyClass {} public class [3] : System.Attribute { public string Version { get; set; } }
The attribute is used as [VersionInfo(Version = "1.0")]. The class name is VersionInfoAttribute but usage drops the 'Attribute' suffix. Named parameters correspond to public properties.