Microsoft Certified Solutions Developer (MCSD) Certification Practice Test

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for the Microsoft Certified Solutions Developer (MCSD) Certification Exam. Practice with flashcards and multiple choice questions. Master each topic with hints and insights. Achieve your certification goals!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


How do you create a custom attribute in C#?

  1. By implementing the IComparable interface

  2. By inheriting from System.Attribute

  3. By defining it in an enumeration

  4. By applying the yield keyword

The correct answer is: By inheriting from System.Attribute

To create a custom attribute in C#, you define a new class that inherits from the System.Attribute class. This inheritance is essential because it provides the necessary framework for the custom attribute to function within the C# type system. Attributes in C# are a way to add metadata to your code elements, such as classes, methods, properties, and other structures, allowing developers to attach additional information that can be retrieved at runtime using reflection. When you inherit from System.Attribute, you can also define constructors and properties that allow the attribute to be configured when it is applied to a code element. For example, you can create an attribute that specifies permissions, validation rules, or any other metadata pertinent to your application. The other choices do not relate to the creation of custom attributes: - Implementing the IComparable interface is related to enabling comparison operations on instances of a class, not to attributes. - Defining something in an enumeration concerns creating a set of named constants rather than defining custom metadata. - Applying the yield keyword is utilized in the context of iterator methods to provide a streamlined way to return elements one at a time, which again is unrelated to the concept of attributes. This distinction underscores the importance of the inheritance from System.Attribute as the foundation for defining custom