Bird
Raised Fist0

Which of the following is the correct way to declare an interface in C#?

easy📝 Syntax Q12 of Q15
C Sharp (C#) - Interfaces
Which of the following is the correct way to declare an interface in C#?
Aenum IExample { DoWork };
Bclass IExample { void DoWork(); }
Cinterface IExample { void DoWork(); }
Dstruct IExample { void DoWork(); }
Step-by-Step Solution
Solution:
  1. Step 1: Identify interface syntax

    In C#, interfaces are declared using the keyword interface followed by the name and method signatures.
  2. Step 2: Check other options

    Options A, B, and C use enum, class, and struct keywords, which are not for interfaces.
  3. Final Answer:

    interface IExample { void DoWork(); } -> Option C
  4. Quick Check:

    Interface keyword = interface declaration [OK]
Quick Trick: Look for 'interface' keyword to declare interfaces [OK]
Common Mistakes:
MISTAKES
  • Using class or struct instead of interface
  • Missing method signature semicolon
  • Confusing enums with interfaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes