none
What are the default access modifiers in C# ?

    Question

  • Hi , 

    what are the default access modifiers for the following .

    1. Class

    2. Methods

    3. Variables

    4. Properties

    5. Abstract Class

    6. Abstract methods

    7. Sealed class

    8. sealed methods

    9. delegates

    10. Events

    11. Indexers

    Thursday, December 18, 2014 11:52 AM

Answers

  • Hi Amal_ES

    Non-nested types, enumeration and delegate accessibilities (may only have internal or public accessibility)

                         | Default   | Permitted declared accessibilities
    ------------------------------------------------------------------
    namespace            | public    | none (always implicitly public)
    
    enum                 | public    | none (always implicitly public)
    
    interface            | internal  | public, internal
    
    class                | internal  | public, internal
    
    struct               | internal  | public, internal
    
    delegate             | internal  | public, internal

    Nested type and member accessiblities

                         | Default   | Permitted declared accessibilities
    ------------------------------------------------------------------
    namespace            | public    | none (always implicitly public)
    
    enum                 | public    | none (always implicitly public)
    
    interface            | public    | none
    
    class                | private   | All¹
    
    struct               | private   | public, internal, private²
    
    delegate             | private   | All¹
    
    constructor          | private   | All¹
    
    interface member     | public    | none (always implicitly public)
    
    method               | private   | All¹
    
    field                | private   | All¹
    
    user-defined operator| none      | public (must be declared public)

    ¹ All === public, protected, internal, private, protected internal

    ² structs cannot inherit from structs or classes (although they can, interfaces), hence protected is not a valid modifier

    For more detaild information, please see:

    http://msdn.microsoft.com/en-us/library/ba0a1yw2.aspx
    http://msdn.microsoft.com/en-us/library/ms173121.aspx
    http://msdn.microsoft.com/en-us/library/cx03xt0t.aspx

    The above information, I just refer to What are the Default Access Modifiers in C#? This is a good summary.

    Good day!

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, December 19, 2014 2:25 AM
    Moderator