Access Modifiers with Interfaces

42,962

Since C# 8.0 you can have access modifier inside the interface. See this post C# 8 Interfaces: Public, Private, and Protected Members


Before C# 8.0

You should see:

Access Modifier - MSDN

Interfaces declared directly within a namespace can be declared as public or internal and, just like classes and structs, interfaces default to internal access. Interface members are always public because the purpose of an interface is to enable other types to access a class or struct. No access modifiers can be applied to interface members.

(For your questions)

Can we use Access Modifier with Interface

Yes, they can be declared as public or internal

By default Are inteface internal

Yes.

what about Access Modfiers with Inteface members.

They are public. No access modifiers can be applied to interface members.

Share:
42,962
Saurabh Mahajan
Author by

Saurabh Mahajan

Updated on June 04, 2022

Comments

  • Saurabh Mahajan
    Saurabh Mahajan almost 2 years

    I am new to .net C#. I am learning about interfaces.

    1. Can we use access modifiers with interfaces, if so, which are valid?
    2. By default, are interfaces internal?
    3. Can we use access modifiers on interface members, if so, which are valid?