locked
Access Modifier RRS feed

  • Question

  • What is the default access modifier of a class, when nothing is mentioned specifically ?

    Kunal Prasad

    Wednesday, May 9, 2012 5:49 AM

Answers

  • Internal is the default if no access modifier is specified.

    More on this topic http://msdn.microsoft.com/en-us/library/ms173121.aspx


    A.m.a.L Hashim
    Microsoft Most Valuable Professional
    My Blog - Dot Net Goodies

    Wednesday, May 9, 2012 6:03 AM
  • It's internal if it's top level, and private if it's an inner class.

    That said, I would highly discourage you from every relying on this.  You should always explicitly type out the access modifier for all classes/methods/properties/fields.  First off, many people don't remember the default modifiers, so if you intentionally leave it off future readers of your code may either need to go look it up, or mis-remember what it is.  Second, the defaults vary between languages, so people working in several languages, or people who have more of a background in another language, will either not know the defaults or think that they are something other than what they are.  This leads to confusion.  Finally, when you omit the access specifier future readers will often wonder whether you intentionally omitted it because you wanted the default value or if you simply forgot to add a specifier and that you actually meant to have something different.  This could result in someone else "fixing" your code by putting in another specifier and breaking something or causing other problems of some sort.


    Thursday, May 10, 2012 3:57 AM
  • The default access modifier of a class is "internal". The The access level for class, struct members, including nested classes and structs is "private".

    You can get more details int the following msdn

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


    Thanks and Regards Selvam http://www15.brinkster.com/selvamselvam/

    Thursday, May 10, 2012 6:41 AM

All replies

  • Internal is the default if no access modifier is specified.

    More on this topic http://msdn.microsoft.com/en-us/library/ms173121.aspx


    A.m.a.L Hashim
    Microsoft Most Valuable Professional
    My Blog - Dot Net Goodies

    Wednesday, May 9, 2012 6:03 AM
  • Hi Kunal,

    What is the default access modifier of a class, when nothing is mentioned specifically ? Private


    Sai Kumar K http://www.santoshtechnologies.com http://saimaterial.wordpress.com

    Wednesday, May 9, 2012 9:13 AM
  • It's internal if it's top level, and private if it's an inner class.

    That said, I would highly discourage you from every relying on this.  You should always explicitly type out the access modifier for all classes/methods/properties/fields.  First off, many people don't remember the default modifiers, so if you intentionally leave it off future readers of your code may either need to go look it up, or mis-remember what it is.  Second, the defaults vary between languages, so people working in several languages, or people who have more of a background in another language, will either not know the defaults or think that they are something other than what they are.  This leads to confusion.  Finally, when you omit the access specifier future readers will often wonder whether you intentionally omitted it because you wanted the default value or if you simply forgot to add a specifier and that you actually meant to have something different.  This could result in someone else "fixing" your code by putting in another specifier and breaking something or causing other problems of some sort.


    Thursday, May 10, 2012 3:57 AM
  • The default access modifier of a class is "internal". The The access level for class, struct members, including nested classes and structs is "private".

    You can get more details int the following msdn

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


    Thanks and Regards Selvam http://www15.brinkster.com/selvamselvam/

    Thursday, May 10, 2012 6:41 AM