473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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.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
Mar 5 '07 #1
2 1745
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.
-----------------------------
<Morten71wrote in message
news:43********************************@4ax.com...
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

Mar 6 '07 #2
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" <Ro****@NoSpam.yah.nonewrote in message
news:46******************************@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.
-----------------------------
<Morten71wrote in message
news:43********************************@4ax.com...
>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


Mar 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Christian Meier | last post by:
Hi dear programmers I looked for the difference between private and protected inheritance, but couldn't find anything. Here is my sample code: #include <iostream> using std::cout; using...
3
by: seesaw | last post by:
Compared to "public", how does "private/protected" in inheritance change relationship between classes what is the purpose to define constructor as "private/protected"? is there any usage to...
2
by: MJ | last post by:
Hi I have a following sample code class base and class derived. I have inherited the base class as private and tried to compile the code its giving an error "conversion from 'class derived *' to...
12
by: Manolis | last post by:
Hi, I was wondering if there is any way to make two objects of the same class to be able to access each other's private data, like this: class A { public: void access( const A& a )...
8
by: __PPS__ | last post by:
Hello everybody, today I had another quiz question "if class X is privately derived from base class Y what is the scope of the public, protected, private members of Y will be in class X" By...
6
by: Ken Varn | last post by:
I have an ASP.NET application that is calling a custom class that is trying to parse all of the members of my Page object using Type.GetMembers(). The problem that I am having is that private...
7
by: My4thPersonality | last post by:
1st, simple question, is there a protected in C#? I mean a comparable keyword like the C++ protected, which defines a member as accessable for decendants, but not for the outside world. Then,...
4
by: newbie120 | last post by:
Hi all maybe its just been a long day, but i have a question about call access modifiers in C#. Consider the following code. namespace Application { private class Class1 { int i;
5
by: JamesO | last post by:
Hello all, Is there a way to make a class private to the namespace so that other classes in the namespace can see and use it but noone outside a namespace can see or use it? Feel free to send...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.