-1

I remember that interface is public by default. Am I wrong? When I tried to implement a "public static" method from an interface. VS told me that the method in the interface is less accessible than the "public static" one. When I added public to the interface it fixed. Isn't interface public by default?

interface IDoubleFloatEventInvoker {
 void AddListener(EventName eventName, UnityAction<float, float> unityAction);
}

public static void AddInvoker(EventName eventName, IDoubleFloatEventInvoker invoker)
{
    foreach (UnityAction<float, float> listener in doubleFloatListeners[eventName])
    {
        invoker.AddListener(eventName, listener);
    }
    doubleFloatInvokers[eventName].Add(invoker);
}

"VS says IDoubleFloatEventInvoker is less accessible than the AddInvoker function"

Frank Sun
  • 49
  • 1
  • 6
  • 1
    Possible duplicate of [Default visibility for C# classes and members (fields, methods, etc.)?](https://stackoverflow.com/questions/3763612/default-visibility-for-c-sharp-classes-and-members-fields-methods-etc) – mjwills Apr 02 '19 at 23:57

1 Answers1

5

Interface members are public, but the interface itself will default to internal if no accessibility is set, in the same way a class will.

As far as the members being public, that's not exactly 'by default': they are always public, and attempting to set an accessibility on them will result in a compilation error.

Jonathon Chase
  • 9,396
  • 21
  • 39