C# - Attributes Question and Answer

C# - Attributes Question and Answer
1. The [Serializable()] attribute gets inspected at
  • Compile-time
  • Run-time
  • Design-time
  • Linking-time
Show Answer
2. Which of the following are correct ways to specify the targets for a custom attribute?
  • By applying AttributeUsage to the custom attribute's class definition.
  • By applying UsageAttribute to the custom attribute's class definition.
  • Once an attribute is declared it applies to all the targets.
  • By applying AttributeUsageAttribute to the custom attribute's class definition.
Show Answer
3. Which of the following are correct ways to pass a parameter to an attribute?

    By value
    By reference
    By address
    By position
    By name
  • 1, 2
  • 1, 2, 3
  • 4, 5
  • All of the above
Show Answer
4. Which of the following statements are correct about inspecting an attribute in C#.NET?

    An attribute can be inspected at link-time.
    An attribute can be inspected at compile-time.
    An attribute can be inspected at run-time.
    An attribute can be inspected at design-time.

  • 1, 2
  • 3, 4
  • 1, 3, 4
  • All of the above
Show Answer
5. Which of the following statements are correct about Attributes used in C#.NET?
  • If there is a custom attribute BugFixAttribute then the compiler will look ONLY for the BugFix attribute in the code that uses this attribute.
  • To create a custom attribute we need to create a custom attribute structure and derive it from System.Attribute.
  • To create a custom attribute we need to create a class and implement IAttribute interface in it.
  • If a BugFixAttribute is to receive three parameters then the BugFixAttribute class should implement a zero-argument constructor.
Show Answer
6. Which of the following statements are correct about Attributes in C#.NET?

    On compiling a C#.NET program the attibutes applied are recorded in the metadata of the assembly.
    On compilation all the attribute's tags are deleted from the program.
    It is not possible to create custom attributes..
    The attributes applied can be read from an assembly using Reflection class.
    An attribute can have parameters.
  • 1 and 2 only
  • 2 and 4 only
  • 1, 4 and 5 only
  • All of the above
Show Answer
7. Which of the following correctly describes the contents of the filename AssemblyInfo.cs?
  • It contains method-level attributes.
  • It contains class-level attributes.
  • It contains assembly-level attributes.
  • It contains structure-level attributes.
Show Answer
8. It possible to create a custom attribute that can be applied only to specific programming element(s) like ____ .
  • Classes
  • Methods
  • Classes and Methods
  • Classes, Methods and Member-Variables
Show Answer
9. Which of the following CANNOT be a target for a custom attribute?
  • Enum
  • Event
  • Delegate
  • Interface
Show Answer
10. Once applied which of the following CANNOT inspect the applied attribute?
  • CLR
  • Linker
  • ASP.NET Runtime
  • Visual Studio.NET
Show Answer
Questions and Answers for Competitive Exams Various Entrance Test