Interface Members Are Implicitly Public

When you declare an interface, you cannot use access modifiers on interface’s member.  An interface makes a collection of members available to code that accesses a class implementing that interface.  So it makes sense that the interface members are public.
1
2
3
4
5
public interface IBark
{
    int BarkCount { get; set; }
    void Bark(string woofSound, int count);
}
When you implement an interface, you must mark the interface members as public.
1
2
3
4
5
6
7
8
9
10
public class Dog : IBark
{
    public int BarkCount { get; set; }
 
    public void Bark(string woofSound, int count)
    {
        for (int i = 1; i <= count; i++)
            Console.WriteLine(woofSound);
    }
}
If you implement the interface explicitly, the members are implicitly public and you cannot mark them with access modifiers.


1
2
3
4
5
6
7
int IBark.BarkCount { get; set; }
 
void <span class="skimlinks-unlinked">IBark.Bark(string</span> woofSound, int count)
{
    for (int i = 1; i <= count; i++)
        Console.WriteLine(woofSound);
}