0
0
C Sharp (C#)programming~10 mins

Attribute declaration syntax in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to apply a simple attribute named MyAttribute.

C Sharp (C#)
[[1]]
public class MyClass {}
Drag options to blanks, or click blank then click option'
Apublic
BAttribute
Cclass
DMyAttribute
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the square brackets.
Using 'class' instead of the attribute name.
2fill in blank
medium

Complete the code to declare a custom attribute class named SampleAttribute.

C Sharp (C#)
public class [1] : System.Attribute {}
Drag options to blanks, or click blank then click option'
ASample
BSampleAttribute
CAttribute
DCustomAttribute
Attempts:
3 left
💡 Hint
Common Mistakes
Not inheriting from System.Attribute.
Missing the 'Attribute' suffix in the class name.
3fill in blank
hard

Fix the error in the attribute usage syntax.

C Sharp (C#)
[Obsolete[1]]
public void OldMethod() {}
Drag options to blanks, or click blank then click option'
A()
B[]
C{}
D<>
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces instead of parentheses.
Omitting parentheses when parameters are expected.
4fill in blank
hard

Fill both blanks to declare an attribute with a positional parameter.

C Sharp (C#)
public class [1] : System.Attribute {
    public [2](string name) {}
}
Drag options to blanks, or click blank then click option'
AAuthorAttribute
BMyAttribute
CAuthorAttr
DAuthor
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same name for class and constructor.
Not matching constructor name to class name without 'Attribute'.
5fill in blank
hard

Fill all three blanks to declare and use a named parameter in an attribute.

C Sharp (C#)
[[1](Version = [2])]
public class MyClass {}

public class [3] : System.Attribute {
    public string Version { get; set; }
}
Drag options to blanks, or click blank then click option'
AVersionInfo
B"1.0"
CVersionInfoAttribute
D"v1"
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'Attribute' suffix in usage.
Using incorrect string value syntax.