locked
C# Access modifiers RRS feed

  • Question

  • Hello all,

     

     I just wanted to know how can we use the access modifiers on a class and an Interface.

     I think we can use all access modifiers as required  on a class. But can I use an access modifier(s) on an interface?

    Explain with example.

     

     

    Thanks,

     


    Kannalu.

    Sunday, September 19, 2010 10:54 PM

Answers

  • I'm not 100% sure what you're asking, but I think the answer is that since Interfaces can only have public access, you can't even specify the public modifier in the Interface definition (you'll get a compiler error).
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Marked as answer by Kannalu Monday, September 20, 2010 1:07 AM
    Sunday, September 19, 2010 11:29 PM

All replies

  • I'm not 100% sure what you're asking, but I think the answer is that since Interfaces can only have public access, you can't even specify the public modifier in the Interface definition (you'll get a compiler error).
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Marked as answer by Kannalu Monday, September 20, 2010 1:07 AM
    Sunday, September 19, 2010 11:29 PM
  • The members of an interface are public, but the interface itself can have the same access modifiers as a class.
    Sunday, September 19, 2010 11:38 PM
  • This is from the C# Interface specification:

    " Interfaces members are automatically public, and they cannot include any access modifiers."

    Here is the link:

    http://msdn.microsoft.com/en-us/library/ms173156.aspx

    Hope this helps.


    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Sunday, September 19, 2010 11:42 PM