---
title: "Interfaces can have private methods"
description: "Let's drop some \"useless\" knowledge here. Interfaces can have private methods. This comes with the C# 8 feature: \"Default interface methods\"."
updated: 2023-10-25
tags: ["C#", ".NET"]
canonical: "https://steven-giesel.com/blogPost/03957748-73b3-40f9-a9f7-cc95501a3a8e/interfaces-can-have-private-methods"
---

# Interfaces can have private methods

Let's drop some "useless" knowledge here. Interfaces can have private methods. This comes with the C# 8 feature: "Default interface methods".

Default interface methods allow us to define a default implementation for a method in an interface. This is useful when we want to add a new method to an interface, but we don't want to break all the classes that implement that interface. Something like that:

```csharp
public interface IMyInterface
{
    public void MyMethod()
    {
        // Do something
    }
}

public class MyClass : IMyInterface
{
    // I don't need to implement MyMethod
}
```

But when using it, we can't call `MyMethod` from `MyClass`:

```csharp
var myClass = new MyClass();
myClass.MyMethod(); // This won't compile

IMyInterface myInterface = myClass;
myInterface.MyMethod(); // This will compile
```

And to make that mess a bit messier, we can also refactor out things that are private inside the interface:

```csharp
public interface IMyInterface
{
    public void MyMethod()
    {
        MyPrivateMethod();
    }

    private void MyPrivateMethod()
    {
        // Do something
    }
}
```

I am not the biggest fan of this feature, but it's there, and it's good to know about it.