Private - Protected

  • Thread starter Thread starter RobinS
  • Start date Start date
R

RobinS

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.
 
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.
 
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.EventArgs) _
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.EventArgs) _
Handles btn.Click

End Sub

Why the difference? And should I care?

Morten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top