Private - Protected

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

    #1

    Private - Protected

    Just curious.

    In VB, if I, from design-mode in vs2005, double-click a button (or any
    other control), the code-behind file opens and the default declaration
    is automatically inserted with method visibility Protected:

    Protected Sub btn_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArg s) _
    Handles btn.Click

    End Sub

    However, if I, manually switch to the code-behind file, select the
    control (btn) and select the Click event from the declaration drop
    down list I get the same sub but with visibility Private:

    Private Sub btn_Click(ByVal sender As Object, _
    ByVal e As System.EventArg s) _
    Handles btn.Click

    End Sub

    Why the difference? And should I care?

    Morten
  • RobinS

    #2
    Re: Private - Protected

    When I double-click a button in VS2005, it makes my sub Private, not
    Protected. I can't imagine why it would make it protected.

    Robin S.
    -----------------------------
    <Morten71wrot e in message
    news:43rpu29ai7 6og0uuitj3ra058 3oeccpdfv@4ax.c om...
    Just curious.
    >
    In VB, if I, from design-mode in vs2005, double-click a button (or any
    other control), the code-behind file opens and the default declaration
    is automatically inserted with method visibility Protected:
    >
    Protected Sub btn_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArg s) _
    Handles btn.Click
    >
    End Sub
    >
    However, if I, manually switch to the code-behind file, select the
    control (btn) and select the Click event from the declaration drop
    down list I get the same sub but with visibility Private:
    >
    Private Sub btn_Click(ByVal sender As Object, _
    ByVal e As System.EventArg s) _
    Handles btn.Click
    >
    End Sub
    >
    Why the difference? And should I care?
    >
    Morten

    Comment

    • Scott M.

      #3
      Re: Private - Protected

      Private means that the procedure is only available to be called from within
      the class code.

      Protected means the same thing PLUS the procedure can also be called from
      classes that inherit from the current class.

      It is always best, when choosing scope (accessibility) to start witth the
      samllest scope (Private) and only increase it if necessary.



      "RobinS" <RobinS@NoSpam. yah.nonewrote in message
      news:46GdnUIu5q OKIXHYnZ2dnUVZ_ oKnnZ2d@comcast .com...
      When I double-click a button in VS2005, it makes my sub Private, not
      Protected. I can't imagine why it would make it protected.
      >
      Robin S.
      -----------------------------
      <Morten71wrot e in message
      news:43rpu29ai7 6og0uuitj3ra058 3oeccpdfv@4ax.c om...
      >Just curious.
      >>
      >In VB, if I, from design-mode in vs2005, double-click a button (or any
      >other control), the code-behind file opens and the default declaration
      >is automatically inserted with method visibility Protected:
      >>
      >Protected Sub btn_Click(ByVal sender As System.Object, _
      > ByVal e As System.EventArg s) _
      > Handles btn.Click
      >>
      >End Sub
      >>
      >However, if I, manually switch to the code-behind file, select the
      >control (btn) and select the Click event from the declaration drop
      >down list I get the same sub but with visibility Private:
      >>
      >Private Sub btn_Click(ByVal sender As Object, _
      > ByVal e As System.EventArg s) _
      > Handles btn.Click
      >>
      >End Sub
      >>
      >Why the difference? And should I care?
      >>
      >Morten
      >
      >

      Comment

      Working...