Skip to content
dreamcode
dreamcode
Map
Interfaces
Lesson 14 of 21
+15 XP on finish
C# INTERMEDIATEChapter 4 · C# Intermediate

Interfaces

An interface is a contract. It declares properties and methods without implementations. Any class that implements the interface must provide the concrete logic.

Worked example
interface ISkyGlow {
    void Glow();
}

class Star : ISkyGlow {
    public void Glow() {
        Console.WriteLine("Star shines");
    }
}

How it reads

  • interface ISkyGlow defines the contract name
  • class Star : ISkyGlow implements the interface contract
Cloud tip: Interface names in C# are traditionally prefixed with a capital 'I', such as IDisposable or IEnumerable.

Check your understanding

0 / 2

Answer all 2 to complete this lesson and earn 15 XP.

  1. 1. Can an interface in C# contain implementation code for its methods by default (pre-C# 8)?
  2. 2. What prefix is conventionally used for interface names in C#?
Answer every question to unlock the next lesson.