locked
Whats the default access specifier in C#.net? RRS feed

  • Question

  • C#: Whats the default access specifier in C#.net?
    ---Sri's
    • Moved by Liliane Teng Monday, June 21, 2010 1:56 AM a problem related to C# (From:Visual Basic General)
    Friday, June 18, 2010 8:17 PM

Answers

  • The default accessibility of top-level types is internal.

    The default accessibility of class and struct members is private.

    The only possible accessibility of interface and enum members is public.

    • Marked as answer by Liliane Teng Saturday, June 26, 2010 2:26 PM
    Friday, June 25, 2010 12:37 PM
  • Hello,
    Thanks for your post.
    Private is the default access specifier in C#.
    More information, you can see:
    http://msdn.microsoft.com/en-us/library/ba0a1yw2%28VS.80%29.aspx
    (Accessibility Levels (C# Reference))

    Best regards,
    Liliane


    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Marked as answer by Liliane Teng Saturday, June 26, 2010 2:26 PM
    Friday, June 25, 2010 10:35 AM

All replies

  • Friday, June 18, 2010 8:25 PM
  • Hi My Best Solutions,

    In addition to Joes' reply see the other Visual C# forums here.>>

    http://social.msdn.microsoft.com/Forums/en-US/category/visualcsharp


    Regards, John : Trying hard for another goal into the .Net!!
    • Proposed as answer by Cor Ligthert Saturday, June 19, 2010 8:02 AM
    • Marked as answer by Liliane Teng Friday, June 25, 2010 10:27 AM
    • Unmarked as answer by Liliane Teng Friday, June 25, 2010 10:27 AM
    Saturday, June 19, 2010 4:07 AM
  • Hello,
    Thanks for your post.
    Private is the default access specifier in C#.
    More information, you can see:
    http://msdn.microsoft.com/en-us/library/ba0a1yw2%28VS.80%29.aspx
    (Accessibility Levels (C# Reference))

    Best regards,
    Liliane


    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Marked as answer by Liliane Teng Saturday, June 26, 2010 2:26 PM
    Friday, June 25, 2010 10:35 AM
  • The default accessibility of top-level types is internal.

    The default accessibility of class and struct members is private.

    The only possible accessibility of interface and enum members is public.

    • Marked as answer by Liliane Teng Saturday, June 26, 2010 2:26 PM
    Friday, June 25, 2010 12:37 PM
  • i hope it will help,

    default access specifiers in c#,

    • method: private
    • members (unless an interface or enum): private (including nested classes)
    • members (of interface or enum): public
    • constructor: protected
    • delegate: internal
    • interface: internal
    • explicitly implemented interface member: public!

     

    Thanks,

    Monday, October 31, 2011 7:31 AM
  • default access specifiers in c#,

    • method: private
    • members (unless an interface or enum): private (including nested classes)
    • members (of interface or enum): public
    • constructor: protected
    • delegate: internal
    • interface: internal
    • explicitly implemented interface member: public!

     


    Close, but not exact.

    • constructor: private
    • delegate: internal (top-level) or private (nested)
    • interface: internal (top-level) or private (nested)
    • explicitly implemented interface member: private (mandatory)

    All are covered by the three cases in my previous post.

    Monday, October 31, 2011 10:25 AM
  • It is Internal by default ...

    Check the access specifier in detail....

    I think it will be helpful.....

    Monday, August 20, 2012 11:53 AM
  • Some things wrong here:

    - this thread has been already answered two years ago;

    - the default specifier is not always internal (check the replies marked as answer).

    Some suggestions for your site:

    - don't confuse scope and accessibility: scope of a member is always the body of the class where it is defined whatever the accessibility;

    - don't confuse DLL, assembly and namespaces: the same namespace can be shared between assemblies and distinct namespace can exist within one assembly;

    - your "specifying accessibility from outside the class" image doesn't show at all what the title suggests;

    - in that same image, you write that the type of variable tells what kind of object is allocated; in fact, the type at left of the name of the variable tells what the static type of the variable is while the type at right of the 'new' operator tells what kind of object to allocate.

    Monday, August 20, 2012 2:03 PM