Object-Oriented C#

Interfaces and Abstraction

Define capabilities that unrelated types can implement.

Introduction

Interfaces describe what an object can do without dictating its storage or inheritance hierarchy.

The SendAll method depends only on INotifier, making new notification channels easy to add and test.

Runnable C# example

C#
Run code →
Program.cs
using System;

interface INotifier { void Send(string message); }
class EmailNotifier : INotifier { public void Send(string message) => Console.WriteLine($"Email: {message}"); }

class Program
{
    static void Main()
    {
        INotifier notifier = new EmailNotifier();
        notifier.Send("Build complete");
    }
}
Result of running the code
Email: Build complete

Practice with the debugger

Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.

Practice with a challenge

Use what this lesson covers to solve a real problem. Each challenge runs in your browser with instant tests and an AI review.

All challenges