Is no declaration is private

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ad

    Is no declaration is private

    When I declare a varible in class like below:

    Is ( string sName;)
    equal to
    (private string sName;)

    ----------------------------------------------------------------------------

    public class StUnit
    {
    string sName;

    public StUnit()
    {

    }
    }


  • Jon Skeet [C# MVP]

    #2
    Re: Is no declaration is private

    ad <ad@wfes.tcc.ed u.tw> wrote:[color=blue]
    > When I declare a varible in class like below:
    >
    > Is ( string sName;)
    > equal to
    > (private string sName;)
    >
    > ----------------------------------------------------------------------------
    >
    > public class StUnit
    > {
    > string sName;
    >
    > public StUnit()
    > {
    >
    > }
    > }[/color]

    Yes. The easy-to-remember rule for C# is that the default is always the
    most private access that you could declare. So for a top-level class,
    it's "internal", for static and member variables it's private, etc.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...