C#.NET — Which members can be declared inside an interface? Consider: 1) Properties 2) Methods 3) Enumerations 4) Events 5) Structures

Difficulty: Easy

Correct Answer: 1, 2, 4

Explanation:


Introduction / Context:
C# interfaces specify contracts. Knowing which members are allowed within an interface definition is essential for proper API design.



Given Data / Assumptions:

  • Standard C# rules apply for interface declarations.
  • We compare typical members: properties, methods, events vs. type declarations like enums/structs.


Concept / Approach:
Interfaces can declare members that describe behavior: methods, properties, events, and indexers. They do not declare fields. Type declarations (enums, structs, classes) are not declared inside an interface in classic C# usage for this curriculum.



Step-by-Step Solution:

Evaluate 1) Properties → allowed in interfaces.Evaluate 2) Methods → allowed in interfaces.Evaluate 3) Enumerations → not declared inside interfaces in this context.Evaluate 4) Events → allowed in interfaces.Evaluate 5) Structures → not declared inside interfaces in this context.


Verification / Alternative check:
Write a small interface: interface IEx { int P { get; set; } event EventHandler E; void Do(); } — compiles. Attempt to place a nested enum or struct in the interface and note it is outside the scope of this syllabus and not used for typical design.



Why Other Options Are Wrong:

  • A/C/D include members not declared in interfaces here (enums/structs).
  • E is incorrect because 1, 2, and 4 are valid.


Common Pitfalls:
Confusing interface members (behavioral contracts) with type definitions, which belong at the namespace or type level, not inside an interface for this exam.



Final Answer:
1, 2, 4

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion