No results found for the specified position. What are attributes? C# Beginner Mock Interview

MockQuestions

C# Beginner Mock Interview

Question 3 of 20 for our C# Beginner Mock Interview

Get More Information About Our C# Beginner Interview Questions

Question 3 of 20

What are attributes?

Attributes are keyword-like declarative descriptions that provide useful metadata for methods, properties, and other fields within your classes. When your code is compiled, these descriptions are discoverable through reflection and provides the user of the class with other helpful information. Attributes can be applied at the class and assembly level.

/**

This example shows how you would you the ObsoleteAttribute to communicate to the user of the method to not use it and to use another method instead
**/

    [Obsolete("This method will no longer be supported in future versions.  Please use MethodThatShouldBeUsed() instead")]
        public static void MethodWithAnAttribute() { }

        public static void MethodThatShouldBeUsed() { }


/** When you compile the code above, you will see a compiler warning: 
'Program.MethodWithAnAttribute()' is obsolete: 'This method will no longer be supported in future versions.  Please use MethodThatShouldBeUsed() instead'
**/

Written by on May 20th, 2021

Next Question

How to Answer: What are attributes?

Advice and answer examples written specifically for a C# Beginner job interview.

  • 3. What are attributes?

      Attributes are keyword-like declarative descriptions that provide useful metadata for methods, properties, and other fields within your classes. When your code is compiled, these descriptions are discoverable through reflection and provides the user of the class with other helpful information. Attributes can be applied at the class and assembly level.

      /**
      
      This example shows how you would you the ObsoleteAttribute to communicate to the user of the method to not use it and to use another method instead
      **/
      
          [Obsolete("This method will no longer be supported in future versions.  Please use MethodThatShouldBeUsed() instead")]
              public static void MethodWithAnAttribute() { }
      
              public static void MethodThatShouldBeUsed() { }
      
      
      /** When you compile the code above, you will see a compiler warning: 
      'Program.MethodWithAnAttribute()' is obsolete: 'This method will no longer be supported in future versions.  Please use MethodThatShouldBeUsed() instead'
      **/

      Written by Edward Danganan on May 10th, 2021